結果

問題 No.345 最小チワワ問題
ユーザー kmtrc130
提出日時 2019-03-18 15:46:16
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 833 ms
コンパイル使用メモリ 109,204 KB
実行使用メモリ 26,752 KB
最終ジャッジ日時 2024-10-01 05:15:03
合計ジャッジ時間 2,634 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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;

class Program
{
    public void Solve()
    {
        string S = Console.ReadLine();
        int wCnt = 0;
        string chk = "";
        List<int> cwwCntList = new List<int>();

        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] != 'c') continue;

            wCnt = 0;
            chk = S.Substring(i + 1);
            for (int j = 0; j < chk.Length; j++)
            {
                if (chk[j] != 'w') continue;
                wCnt++;
                if (2 <= wCnt)
                {
                    cwwCntList.Add(j + 2);
                    break;
                }
            }
        }
        Console.WriteLine(cwwCntList.Count == 0 ? -1 : cwwCntList.Min());
    }

    static void Main()
    {
        var solver = new Program();
        solver.Solve();
    }
}
0