結果

問題 No.345 最小チワワ問題
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-05-05 08:51:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,344 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 73,012 KB
実行使用メモリ 51,412 KB
最終ジャッジ日時 2023-10-12 09:36:45
合計ジャッジ時間 4,620 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,560 KB
testcase_01 AC 42 ms
49,156 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 41 ms
49,168 KB
testcase_08 AC 42 ms
49,252 KB
testcase_09 AC 42 ms
49,264 KB
testcase_10 AC 42 ms
49,360 KB
testcase_11 AC 41 ms
49,252 KB
testcase_12 AC 42 ms
49,476 KB
testcase_13 AC 42 ms
49,424 KB
testcase_14 WA -
testcase_15 AC 42 ms
49,264 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 42 ms
49,172 KB
testcase_20 AC 41 ms
49,480 KB
testcase_21 AC 42 ms
49,268 KB
testcase_22 AC 41 ms
49,224 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 42 ms
49,256 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 41 ms
49,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String S = reader.readLine();
        int wCount = 0;
        int firstW = 0;
        int secondW = 0;
        int answer = -1;
        for (int i = S.length() - 1; i >= 0; i--) {
            char current = S.charAt(i);
            if (current == 'w') {
                wCount += 1;
                if (wCount == 1) {
                    firstW = i;
                } else if (wCount == 2) {
                    secondW = i;
                } else {
                    firstW = secondW;
                    secondW = i;
                }

//                System.out.println("first ; " + firstW + " second; " + secondW);
//
            } else if (current == 'c' && wCount >= 2) {
//                System.out.println("c; " + i + "first ; " + firstW + " second; " + secondW);
                answer = firstW - i + 1;
            } else if (current == 'c' && wCount < 2) {
                wCount = 0;
            }
        }
        System.out.println(answer);

    }
}
0