結果

問題 No.345 最小チワワ問題
ユーザー yagi2yagi2
提出日時 2017-04-17 21:32:16
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 684 bytes
コンパイル時間 2,077 ms
コンパイル使用メモリ 71,288 KB
実行使用メモリ 56,084 KB
最終ジャッジ日時 2023-09-26 10:56:28
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
55,404 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 119 ms
55,408 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 119 ms
56,084 KB
testcase_08 AC 118 ms
55,432 KB
testcase_09 AC 118 ms
55,464 KB
testcase_10 AC 119 ms
56,020 KB
testcase_11 AC 126 ms
55,700 KB
testcase_12 AC 122 ms
55,624 KB
testcase_13 AC 122 ms
55,640 KB
testcase_14 AC 120 ms
55,604 KB
testcase_15 AC 118 ms
55,652 KB
testcase_16 AC 118 ms
55,452 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 116 ms
55,672 KB
testcase_20 AC 118 ms
55,560 KB
testcase_21 WA -
testcase_22 AC 124 ms
55,136 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 117 ms
55,304 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 121 ms
55,748 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;
        int wc = 0;
        for(String s : S.split("")) {
            if (c) n++;
            if (s.equals("c")) {
                n = 1;
                c = true;
            }
            if (s.equals("w")) {
                wc++;
                if (wc == 2) {
                    break;
                }
            }
        }

        if (c && wc == 2) {
            System.out.println(n);
        } else {
            System.out.println("-1");
        }
    }
}
0