結果

問題 No.150 "良問"(良問とは言っていない
ユーザー mbanmban
提出日時 2017-01-12 14:28:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 2,184 bytes
コンパイル時間 2,649 ms
コンパイル使用メモリ 105,984 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-04-19 09:43:55
合計ジャッジ時間 3,829 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
17,664 KB
testcase_01 AC 25 ms
17,920 KB
testcase_02 AC 27 ms
17,792 KB
testcase_03 AC 28 ms
17,792 KB
testcase_04 AC 27 ms
17,920 KB
testcase_05 AC 22 ms
17,536 KB
testcase_06 AC 44 ms
17,792 KB
testcase_07 AC 26 ms
17,920 KB
testcase_08 AC 25 ms
17,920 KB
testcase_09 AC 24 ms
17,920 KB
testcase_10 AC 28 ms
17,664 KB
testcase_11 AC 31 ms
17,920 KB
testcase_12 AC 26 ms
17,792 KB
testcase_13 AC 32 ms
17,792 KB
testcase_14 AC 32 ms
17,920 KB
testcase_15 AC 30 ms
17,792 KB
testcase_16 AC 24 ms
17,792 KB
testcase_17 AC 23 ms
17,792 KB
testcase_18 AC 29 ms
17,920 KB
testcase_19 AC 31 ms
17,792 KB
testcase_20 AC 33 ms
17,920 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static private Magatro M = new Magatro();
    static private void Main(string[]args)
    {
        M.Scan();
        M.Solve();
    }
}

public class Scanner
{
    private string[] S;
    private int Index;
    private char Separator;

    public Scanner(char separator = ' ')
    {
        Index = 0;
        Separator = separator;
    }

    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}

public class Magatro
{
    private int T;
    private Scanner Sc = new Scanner();
    private const string good= "good";
    private const string problem = "problem";
    public void Scan()
    {
        T = Sc.NextInt();
    }
    public void Solve()
    {
        for(int i = 0; i < T; i++)
        {
            string S = Sc.Next();
            Console.WriteLine(Anser(S));
        }
    }
    private int Anser(string s)
    {
        int result = int.MaxValue;
        for(int i = 0; i <= s.Length - good.Length - problem.Length; i++)
        {
            for(int j = i + 4; j <= s.Length - problem.Length; j++)
            {
                result = Math.Min(result, Change(s,i,good) + Change(s,j,problem));
            }
        }
        return result;
    }
    private int Change(string s,int index,string b)
    {
        int result = b.Length;
        if (s.Length-index < b.Length) throw new Exception();
        for(int i = 0; i < b.Length; i++)
        {
            if (s[index+i] == b[i]) result--;
        }
        return result;
    }
}
0