結果

問題 No.430 文字列検索
ユーザー YoshiRyuYoshiRyu
提出日時 2016-11-09 22:24:52
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,340 bytes
コンパイル時間 2,362 ms
コンパイル使用メモリ 108,804 KB
実行使用メモリ 21,792 KB
最終ジャッジ日時 2023-08-16 16:37:28
合計ジャッジ時間 6,514 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
21,792 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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();

        int sLength = S.Length;

        int ANS = 0;

        Action<string> act_Search = null;
        act_Search = new Action<string>( ( searchVal ) =>
        {
            int startIndex = 0;

            do  // 一回目は必ず実行する
            {
                int skipInterval  = searchVal.Length;

                // 照合範囲を全体から抽出
                string SPortion = S.Substring( startIndex, searchVal.Length );

                // 合致した場合、結果をインクリメント
                if (searchVal == SPortion)
                {
                    ANS++;
                }

                //// 検索位置をずらす

                // 後ろから探して合致位置を求める
                int idx = searchVal.Substring(0,searchVal.Length - 1).LastIndexOf( SPortion[SPortion.Length - 1] );

                // 見つけたら、ずらす量を求める
                if (idx > -1 && idx != searchVal.Length - 1)
                {
                    skipInterval = (searchVal.Length - (idx + 1));
                }

                startIndex += skipInterval;

            } while (startIndex + searchVal.Length <= sLength);
        });

        while (M-- > 0)
        {
            string C = MyConsole.String();
            
            if (C.Length > S.Length)
            {
                continue;
            }
            else if (C.Length > 1)
            {
                // 文字数が2以上の場合
                act_Search( C );
            }
            else
            {
                // 文字数が1の場合
                ANS += ( sLength - S.Replace( C, "" ).Length );
            }
        }

        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