結果

問題 No.430 文字列検索
ユーザー 14番
提出日時 2016-11-08 02:14:41
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,454 bytes
コンパイル時間 1,305 ms
コンパイル使用メモリ 104,832 KB
実行使用メモリ 23,936 KB
最終ジャッジ日時 2024-11-10 00:12:35
合計ジャッジ時間 4,334 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other AC * 1 TLE * 1 -- * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;
using System.Collections.Generic;

public class Program
{
    public void Proc() {
        Reader.IsDebug = false;
        string text = Reader.ReadLine();
        long ans = 0;

        int wordCount = int.Parse(Reader.ReadLine());
        for(int i=0; i<wordCount; i++) {
            string wrd = Reader.ReadLine();
            int endIdx = text.LastIndexOf(wrd);
            int curr = 0;
            while(endIdx >= 0 && curr <= endIdx) {
                int fnd = text.IndexOf(wrd, curr);
                if(fnd>=0) {
                    ans++;
                    curr=fnd+1;
                } else {
                    break;
                }
            }
        }
        Console.WriteLine(ans);


        
    }


    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"



ABAACABCAACBABABACBBAC
7
A
C
AA
ABB
ABA
BA
CBBAC


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0