結果

問題 No.345 最小チワワ問題
ユーザー SagTokiSagToki
提出日時 2018-05-17 14:50:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,722 bytes
コンパイル時間 4,607 ms
コンパイル使用メモリ 82,632 KB
実行使用メモリ 57,652 KB
最終ジャッジ日時 2023-10-26 04:27:38
合計ジャッジ時間 9,887 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
57,440 KB
testcase_01 AC 134 ms
57,308 KB
testcase_02 AC 133 ms
57,420 KB
testcase_03 AC 129 ms
57,404 KB
testcase_04 AC 127 ms
57,332 KB
testcase_05 AC 130 ms
57,344 KB
testcase_06 AC 117 ms
56,216 KB
testcase_07 AC 133 ms
57,460 KB
testcase_08 AC 137 ms
57,652 KB
testcase_09 AC 132 ms
57,460 KB
testcase_10 AC 137 ms
57,292 KB
testcase_11 AC 134 ms
57,312 KB
testcase_12 AC 138 ms
57,352 KB
testcase_13 AC 135 ms
57,084 KB
testcase_14 AC 132 ms
57,312 KB
testcase_15 AC 131 ms
57,524 KB
testcase_16 AC 132 ms
57,316 KB
testcase_17 AC 131 ms
57,356 KB
testcase_18 AC 138 ms
57,380 KB
testcase_19 AC 130 ms
57,364 KB
testcase_20 AC 133 ms
57,376 KB
testcase_21 AC 128 ms
55,268 KB
testcase_22 AC 133 ms
57,348 KB
testcase_23 AC 129 ms
57,436 KB
testcase_24 AC 131 ms
57,208 KB
testcase_25 AC 130 ms
57,300 KB
testcase_26 AC 131 ms
57,376 KB
testcase_27 AC 131 ms
57,504 KB
testcase_28 AC 133 ms
57,424 KB
testcase_29 AC 130 ms
57,384 KB
testcase_30 AC 134 ms
57,476 KB
testcase_31 AC 127 ms
57,284 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class MinimumChihuahua {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        try{
            String S = scanner.next();
            if(S.length() < 1 || S.length() > 100){
                System.out.println("文字列は1以上100以下の文字数で入力してください");
                System.exit(0);
            }
            Pattern pattern = Pattern.compile(".*[A-Z].*");
            Matcher matcher = pattern.matcher(S);
            if(matcher.find()){
                S = S.toLowerCase();
            }
            
            char[] CS = S.toCharArray();
            ArrayList<Integer> Stock = new ArrayList<>();
            int CountW = 0;
            
            for (int i = 0 ; i < CS.length ;i++){
                if(CS[i] == 'c'){
                    for(int j = i ; j < CS.length ; j++){
                        if(CS[j] == 'w'){
                            CountW++;
                            if(CountW == 2){
                                 Stock.add((j + 1) - i );
                                 break;
                            }
                        }
                    }
                    CountW = 0; 
                }
            }
            
            if(Stock.isEmpty()){
                System.out.println("-1");
            }else{
                Collections.sort(Stock);
                System.out.println(Stock.get(0));
            }
              
        }catch(Exception E){
            System.out.println("予期せぬエラーです");
        }
    }
}
0