結果

問題 No.345 最小チワワ問題
ユーザー MoonOnRain
提出日時 2018-06-29 21:10:15
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 1,252 ms
コンパイル使用メモリ 115,888 KB
実行使用メモリ 26,764 KB
最終ジャッジ日時 2024-09-25 12:15:45
合計ジャッジ時間 3,076 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
        private bool _isEnd;

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

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

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

            return 101;
        }
    }
}
0