結果

問題 No.345 最小チワワ問題
ユーザー SaYaSaYa
提出日時 2016-05-30 23:15:05
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,043 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 76,024 KB
実行使用メモリ 41,784 KB
最終ジャッジ日時 2024-04-16 18:59:20
合計ジャッジ時間 7,419 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
41,196 KB
testcase_01 AC 135 ms
41,248 KB
testcase_02 AC 132 ms
41,040 KB
testcase_03 AC 130 ms
41,784 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 129 ms
41,452 KB
testcase_08 AC 113 ms
40,076 KB
testcase_09 AC 127 ms
41,400 KB
testcase_10 AC 125 ms
41,268 KB
testcase_11 AC 127 ms
41,244 KB
testcase_12 AC 126 ms
41,128 KB
testcase_13 AC 129 ms
41,500 KB
testcase_14 WA -
testcase_15 AC 127 ms
41,512 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 130 ms
41,052 KB
testcase_21 AC 129 ms
41,324 KB
testcase_22 AC 126 ms
41,052 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 128 ms
41,096 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 128 ms
41,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        String input = new Scanner(System.in).next();
        int startIdx = -1;
        int answer = -1;
        CWWState cwwState = CWWState.C;

        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            switch (cwwState) {
                case C:
                    if (c == 'c') {
                        startIdx = i;
                        cwwState = CWWState.W1;
                    }
                    break;
                case W1:
                    if (c == 'w') {
                        cwwState = CWWState.W2;
                    }
                    break;
                case W2:
                    if (c == 'w') {
                        answer = i - startIdx + 1;
                        cwwState = CWWState.C;
                    }
                    break;
            }
        }
        System.out.println(answer);
    }

    private enum CWWState {
        C, W1, W2
    }
}
0