結果

問題 No.430 文字列検索
ユーザー YoshiRyuYoshiRyu
提出日時 2016-11-10 16:04:56
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 209 ms / 2,000 ms
コード長 2,851 bytes
コンパイル時間 7,425 ms
コンパイル使用メモリ 114,244 KB
実行使用メモリ 68,520 KB
最終ジャッジ日時 2024-05-04 01:22:30
合計ジャッジ時間 4,561 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
25,380 KB
testcase_01 AC 209 ms
66,864 KB
testcase_02 AC 165 ms
32,732 KB
testcase_03 AC 173 ms
30,692 KB
testcase_04 AC 26 ms
27,520 KB
testcase_05 AC 26 ms
27,164 KB
testcase_06 AC 24 ms
23,092 KB
testcase_07 AC 24 ms
25,136 KB
testcase_08 AC 208 ms
68,520 KB
testcase_09 AC 30 ms
25,428 KB
testcase_10 AC 38 ms
31,828 KB
testcase_11 AC 189 ms
38,236 KB
testcase_12 AC 196 ms
38,508 KB
testcase_13 AC 195 ms
38,508 KB
testcase_14 AC 183 ms
35,700 KB
testcase_15 AC 179 ms
32,796 KB
testcase_16 AC 175 ms
32,772 KB
testcase_17 AC 173 ms
32,744 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

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();
    }
}
0