結果

問題 No.345 最小チワワ問題
ユーザー yagi2yagi2
提出日時 2017-04-20 12:37:00
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,041 bytes
コンパイル時間 4,690 ms
コンパイル使用メモリ 75,528 KB
実行使用メモリ 58,000 KB
最終ジャッジ日時 2023-09-27 03:16:21
合計ジャッジ時間 9,430 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,664 KB
testcase_01 WA -
testcase_02 AC 115 ms
55,912 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 117 ms
55,956 KB
testcase_08 AC 117 ms
55,620 KB
testcase_09 AC 117 ms
56,368 KB
testcase_10 WA -
testcase_11 AC 119 ms
55,488 KB
testcase_12 AC 117 ms
55,820 KB
testcase_13 AC 115 ms
55,884 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 115 ms
55,484 KB
testcase_20 WA -
testcase_21 AC 114 ms
55,504 KB
testcase_22 AC 115 ms
55,604 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 119 ms
55,624 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 116 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

        List<Integer> cwwList = new ArrayList<>();
        for (int i = 0; i < S.length() - 1; i++) {
            int n = 0;
            if (S.charAt(i) == 'c') {
                int wwCount = 0;
                for (int j = i+1; j < S.length(); j++) {
                   if (S.charAt(j) == 'w') wwCount++;
                   if (wwCount == 2) {
                       n = j+1;
                       break;
                   }

                }
            }
            if (n > 0) {
                cwwList.add(n);
            }
        }

        if (cwwList.size() == 0) {
            System.out.println("-1");
        } else {
            int min = Integer.MAX_VALUE;
            for (Integer n : cwwList) {
                if (min > n) min = n;
            }
            System.out.println(min);
        }
    }
}
0