結果

問題 No.150 "良問"(良問とは言っていない
ユーザー sekiya9311sekiya9311
提出日時 2017-10-01 11:29:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 3,576 bytes
コンパイル時間 1,989 ms
コンパイル使用メモリ 113,728 KB
実行使用メモリ 28,204 KB
最終ジャッジ日時 2024-04-19 09:46:31
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
24,240 KB
testcase_01 AC 25 ms
26,060 KB
testcase_02 AC 25 ms
26,024 KB
testcase_03 AC 24 ms
26,160 KB
testcase_04 AC 25 ms
24,112 KB
testcase_05 AC 25 ms
24,016 KB
testcase_06 AC 34 ms
26,020 KB
testcase_07 AC 26 ms
26,304 KB
testcase_08 AC 25 ms
26,184 KB
testcase_09 AC 26 ms
28,204 KB
testcase_10 AC 27 ms
23,984 KB
testcase_11 AC 28 ms
24,016 KB
testcase_12 AC 27 ms
26,188 KB
testcase_13 AC 27 ms
24,148 KB
testcase_14 AC 28 ms
24,016 KB
testcase_15 AC 28 ms
22,064 KB
testcase_16 AC 25 ms
24,272 KB
testcase_17 AC 26 ms
24,020 KB
testcase_18 AC 28 ms
25,912 KB
testcase_19 AC 27 ms
21,944 KB
testcase_20 AC 28 ms
26,156 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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProgrammingContest
{
    class MainClass
    {
        Scanner sc;
        static void Main(string[] args)
        {
            new MainClass().solve();
        }

        const bool DEBUG = false;  // must check!!
        void solve()
        {
            if (DEBUG)
            {
                string backPath = "..";
                char dirSep = System.IO.Path.DirectorySeparatorChar;
                string inFilePath = backPath + dirSep + backPath + dirSep + "in.txt";
                sc = new Scanner(new System.IO.StreamReader(inFilePath));
            }
            else
            {
                sc = new Scanner();
            }
            int t = sc.NextInt;
            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < t; i++)
            {
                ans.AppendLine(calc(sc.Next).ToString());
            }
            Console.Write(ans);
        }
        const string good = "good";
        const string problem = "problem";
        int calc(string s)
        {
            int L = s.Length;
            int res = (int)1e9;
            for (int i = 0; i < L - good.Length - problem.Length + 1; i++)
            {
                int pre = 0;
                for (int j = 0; j < good.Length; j++)
                {
                    if (s[i + j] != good[j])
                    {
                        pre++;
                    }
                }
                int pre2 = (int)1e9;
                for (int j = i + good.Length; j < L - problem.Length + 1; j++)
                {
                    int pre3 = 0;
                    for (int k = 0; k < problem.Length; k++)
                    {
                        if (s[j + k] != problem[k])
                        {
                            pre3++;
                        }
                    }
                    pre2 = Math.Min(pre2, pre3);
                }
                res = Math.Min(res, pre + pre2);
            }
            return res;
        }
    }

    class Scanner
    {
        Queue<String> buffer;
        char[] sep;
        System.IO.TextReader reader;
        public Scanner(System.IO.TextReader reader = null)
        {
            this.buffer = new Queue<string>();
            this.sep = new char[] { ' ' };
            this.reader = (reader == null ? Console.In : reader);
        }
        private void checkBuffer()
        {
            if (this.buffer.Count == 0)
            {
                String[] sreArray = this.reader.ReadLine().Split(this.sep);
                foreach (String elStr in sreArray)
                {
                    this.buffer.Enqueue(elStr);
                }
            }
        }

        public String Next
        {
            get
            {
                this.checkBuffer();
                return this.buffer.Dequeue();
            }
        }

        public int NextInt
        {
            get
            {
                return int.Parse(this.Next);
            }
        }
        public double NextDouble
        {
            get
            {
                return double.Parse(this.Next);
            }
        }

        public long NextLong
        {
            get
            {
                return long.Parse(this.Next);
            }
        }
        public bool isEmpty
        {
            get
            {
                this.checkBuffer();
                return this.buffer.Count == 0;
            }
        }
    }
}
0