結果

問題 No.345 最小チワワ問題
ユーザー yagi2yagi2
提出日時 2017-04-17 21:29:02
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 764 bytes
コンパイル時間 2,715 ms
コンパイル使用メモリ 72,656 KB
実行使用メモリ 57,784 KB
最終ジャッジ日時 2023-09-26 10:56:20
合計ジャッジ時間 9,220 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
55,528 KB
testcase_01 AC 121 ms
55,716 KB
testcase_02 AC 120 ms
55,144 KB
testcase_03 AC 121 ms
55,360 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 119 ms
55,552 KB
testcase_08 AC 118 ms
55,636 KB
testcase_09 AC 119 ms
55,596 KB
testcase_10 AC 119 ms
55,612 KB
testcase_11 AC 120 ms
55,728 KB
testcase_12 AC 119 ms
55,460 KB
testcase_13 AC 125 ms
55,224 KB
testcase_14 WA -
testcase_15 AC 121 ms
55,856 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 123 ms
55,508 KB
testcase_20 AC 129 ms
55,560 KB
testcase_21 AC 122 ms
55,232 KB
testcase_22 AC 123 ms
55,336 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 122 ms
55,664 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 120 ms
55,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String S = sc.next();

        int n = 0;
        boolean c = false, w1 = false, w2 = false;
        for(String s : S.split("")) {
            if (c) n++;
            if (s.equals("c") && !c && !w1 && !w2) {
                c = true;
                n++;
            }
            if (s.equals("w") && c && !w1 && !w2) {
                w1 = true;
            } else if (s.equals("w") && c && w1 && !w2) {
                w2 = true;
                break;
            }
        }

        if (c && w1 && w2) {
            System.out.println(n);
        } else {
            System.out.println("-1");
        }
    }
}
0