結果

問題 No.345 最小チワワ問題
ユーザー CroweaCrowea
提出日時 2019-01-24 17:49:02
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,101 bytes
コンパイル時間 849 ms
コンパイル使用メモリ 65,740 KB
実行使用メモリ 25,460 KB
最終ジャッジ日時 2023-10-14 09:40:37
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
21,380 KB
testcase_01 AC 57 ms
23,304 KB
testcase_02 AC 56 ms
21,376 KB
testcase_03 AC 56 ms
21,548 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 51 ms
21,192 KB
testcase_08 AC 50 ms
21,096 KB
testcase_09 AC 51 ms
23,280 KB
testcase_10 AC 56 ms
23,536 KB
testcase_11 AC 49 ms
19,196 KB
testcase_12 AC 51 ms
23,356 KB
testcase_13 AC 51 ms
21,076 KB
testcase_14 WA -
testcase_15 AC 56 ms
21,284 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 56 ms
23,496 KB
testcase_20 AC 56 ms
21,268 KB
testcase_21 RE -
testcase_22 AC 55 ms
21,332 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 RE -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 50 ms
21,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var input   = Console.ReadLine();
        var chArr   = input.ToCharArray();
        int first_c = 0;
        int first_w = 0;
        int last_w  = 0;
        int len     = 0;

        if (chArr.Count(x => x == 'c') >= 1 && chArr.Count(x => x == 'w') >= 2)
        {
            input = new string(chArr);
            first_c = input.IndexOf('c');
            first_w = input.IndexOf('w');
            last_w = input.LastIndexOf('w');

            len = (last_w - first_c) + 1;
            input = input.Substring(first_c, len);
            first_c = input.IndexOf('c');
            first_w = input.IndexOf('w');

            for (int i = first_w + 1; i <input.Length; i++)
            {
                if (input[i] == 'w')
                {
                    last_w = i;
                    break;
                }
            }
            input = input.Substring(0, last_w + 1);           
            Console.WriteLine(input.Length);
        }
        else Console.WriteLine("-1");


    }
}
0