結果

問題 No.345 最小チワワ問題
ユーザー MoonOnRainMoonOnRain
提出日時 2018-06-29 21:07:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,381 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 106,788 KB
実行使用メモリ 25,332 KB
最終ジャッジ日時 2023-09-13 15:18:04
合計ジャッジ時間 5,563 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
23,284 KB
testcase_01 AC 52 ms
21,336 KB
testcase_02 AC 53 ms
21,320 KB
testcase_03 AC 53 ms
21,156 KB
testcase_04 WA -
testcase_05 AC 52 ms
19,232 KB
testcase_06 WA -
testcase_07 AC 56 ms
23,196 KB
testcase_08 AC 54 ms
21,332 KB
testcase_09 AC 55 ms
23,232 KB
testcase_10 AC 54 ms
23,284 KB
testcase_11 AC 55 ms
21,196 KB
testcase_12 AC 54 ms
21,200 KB
testcase_13 AC 56 ms
21,192 KB
testcase_14 AC 55 ms
21,220 KB
testcase_15 WA -
testcase_16 AC 54 ms
23,224 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 53 ms
21,256 KB
testcase_21 AC 55 ms
21,260 KB
testcase_22 AC 53 ms
23,248 KB
testcase_23 AC 53 ms
23,136 KB
testcase_24 AC 53 ms
21,388 KB
testcase_25 AC 54 ms
21,168 KB
testcase_26 AC 56 ms
21,344 KB
testcase_27 WA -
testcase_28 AC 57 ms
21,284 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 55 ms
19,112 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;

namespace chiwawa
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            var len = input.Length;

            var chiwawaList = new List<Chiwawa>();

            for (int i = 0; i < len; i++)
            {
                if(input[i] == 'c')
                {
                    chiwawaList.Add(new Chiwawa(i));
                }
                else if(input[i] == 'w')
                {
                    chiwawaList.ForEach(x => x.FindW(i));
                }
            }

            var min = (chiwawaList.Any()) ? chiwawaList.Min(x => x.Length()) : 101;

            Console.WriteLine(min == 101 ? -1 : min);
        }
    }

    public class Chiwawa
    {
        private int _first;
        private int _end;
        private bool _nextIsEnd;

        public Chiwawa(int CIndex)
        {
            _first = CIndex;
            _nextIsEnd = false;
        }

        public void FindW(int WIndex)
        {
            if (_nextIsEnd)
            {
                _end = WIndex;
            }
            else
            {
                _nextIsEnd = true;
            }
        }

        public int Length()
        {
            if(_end > 0) { return _end - _first + 1; }

            return 101;
        }
    }
}
0