結果

問題 No.345 最小チワワ問題
ユーザー S1hoS1ho
提出日時 2017-02-28 15:42:19
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,018 bytes
コンパイル時間 2,374 ms
コンパイル使用メモリ 72,136 KB
実行使用メモリ 56,012 KB
最終ジャッジ日時 2023-09-02 16:53:19
合計ジャッジ時間 7,735 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,760 KB
testcase_01 AC 120 ms
53,816 KB
testcase_02 AC 123 ms
55,596 KB
testcase_03 AC 122 ms
55,784 KB
testcase_04 AC 123 ms
55,636 KB
testcase_05 AC 121 ms
56,012 KB
testcase_06 AC 120 ms
55,708 KB
testcase_07 AC 121 ms
55,656 KB
testcase_08 AC 121 ms
55,920 KB
testcase_09 AC 117 ms
55,512 KB
testcase_10 AC 121 ms
55,744 KB
testcase_11 AC 120 ms
55,700 KB
testcase_12 AC 122 ms
55,776 KB
testcase_13 AC 120 ms
55,788 KB
testcase_14 AC 122 ms
55,512 KB
testcase_15 AC 122 ms
55,428 KB
testcase_16 AC 121 ms
56,000 KB
testcase_17 AC 121 ms
55,432 KB
testcase_18 AC 121 ms
55,496 KB
testcase_19 WA -
testcase_20 AC 125 ms
55,668 KB
testcase_21 AC 121 ms
55,756 KB
testcase_22 AC 121 ms
55,800 KB
testcase_23 AC 122 ms
55,708 KB
testcase_24 AC 120 ms
55,904 KB
testcase_25 AC 119 ms
55,432 KB
testcase_26 AC 120 ms
55,748 KB
testcase_27 WA -
testcase_28 AC 118 ms
55,752 KB
testcase_29 WA -
testcase_30 AC 119 ms
55,704 KB
testcase_31 AC 123 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {

    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        
        String s = scanner.next();
        
        char c;
        
        ArrayList<Integer> list = new ArrayList<>();
        
        for(int i=0;i<s.length();i++){
            c = s.charAt(i);
            if(c == 'c'){
                list.add(i);
            }
        }
        
        int w1;
        int w2;
        
        int min = -1;
        
        for(int i=0;i<list.size();i++){
            
            w1 = s.indexOf("w",list.get(i));
            w2 = s.indexOf("w",w1+1);

            if(w1 != -1 && w2 != -1){
                if(min == -1){
                    min = w2 - (list.get(i) - 1);
                }else if(min > w2 - list.get(i) - 1){
                    min = w2 - (list.get(i) - 1);
                }
            }
            
        }
        
        System.out.println(min);
    }
    
}
0