結果
問題 |
No.345 最小チワワ問題
|
ユーザー |
|
提出日時 | 2018-06-29 21:07:43 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,381 bytes |
コンパイル時間 | 993 ms |
コンパイル使用メモリ | 117,356 KB |
実行使用メモリ | 26,736 KB |
最終ジャッジ日時 | 2024-06-30 23:54:19 |
合計ジャッジ時間 | 2,760 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 WA * 9 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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; } } }