結果
| 問題 |
No.430 文字列検索
|
| コンテスト | |
| ユーザー |
YoshiRyu
|
| 提出日時 | 2016-11-10 16:04:56 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 217 ms / 2,000 ms |
| コード長 | 2,851 bytes |
| コンパイル時間 | 776 ms |
| コンパイル使用メモリ | 108,544 KB |
| 実行使用メモリ | 60,352 KB |
| 最終ジャッジ日時 | 2024-11-10 00:12:44 |
| 合計ジャッジ時間 | 3,591 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class YukiCoder
{
public static void Solve()
{
var S = MyConsole.String();
var M = MyConsole.Int();
string[] MM = new string[M];
for (int i = 0 ; i < M ; i++) MM[i] = MyConsole.String();
var dic = new Dictionary<string, int>();
int sLength = S.Length;
for (int sLen = 0 ; sLen < sLength ; sLen++)
{
string s = "";
// 検索の文字列1から10桁で一文字ずつズラしながら
// 文字列をくり抜いてディクショナリに格納する
for (int mLen = 1 ; mLen < 11 ; mLen++)
{
// 現在位置から後ろの文字を結合させながらディクショナリに追加する
int j = sLen - mLen + 1;
if (j < 0) break;
s = S[j] + s;
// ディクショナリに対して、重複した文字列は登場回数をインクリメント、新規は追加
if (dic.ContainsKey( s )) dic[s]++; else dic.Add( s, 1 );
}
}
int ANS = 0;
// 与えられた検索対象の文字列をキーに登場回数を取得して加算を行う
for (int i = 0 ; i < M ; i++) if (dic.ContainsKey( MM[i] )) ANS += dic[MM[i]];
MyConsole.wLine( ANS.ToString() );
}
public static void Main()
{
MyConsole.Read(); Solve(); MyConsole.Finish();
}
}
public static class MyConsole
{
private static List<string> ReadedLine = new List<string>();
private static char[] buf = new char[1024];
private static int i;
public static void Read()
{
string sr = Console.In.ReadToEnd();
ReadedLine = sr.Split( new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries ).ToList();
Console.SetOut( new StreamWriter( Console.OpenStandardOutput() ) { AutoFlush = false } );
}
public static string String() { return ReadedLine[i++]; }
public static string[] StringSplit() { return ReadedLine[i++].Split( new[] { ' ' } ); }
public static int Int() { return int.Parse( ReadedLine[i++] ); }
public static int[] IntSplit()
{
string[] strs = StringSplit();
int[] ret = new int[strs.Length];
for (int i = 0 ; i < strs.Length ; i++)
{
ret[i] = int.Parse( strs[i] );
}
return ret;
}
public static long Long() { return long.Parse( ReadedLine[i++] ); }
public static double Double() { return double.Parse( ReadedLine[i++] ); }
public static void wLine( string output = null )
{
Console.WriteLine( output );
}
public static void Finish()
{
Console.Out.Flush();
}
}
YoshiRyu