結果

問題 No.345 最小チワワ問題
ユーザー SagTokiSagToki
提出日時 2018-05-17 14:41:15
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,689 bytes
コンパイル時間 3,409 ms
コンパイル使用メモリ 78,336 KB
実行使用メモリ 58,168 KB
最終ジャッジ日時 2023-09-10 22:32:14
合計ジャッジ時間 8,549 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,644 KB
testcase_01 AC 121 ms
55,540 KB
testcase_02 AC 119 ms
55,532 KB
testcase_03 AC 119 ms
55,484 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 119 ms
55,808 KB
testcase_08 AC 123 ms
55,248 KB
testcase_09 AC 121 ms
55,480 KB
testcase_10 AC 122 ms
55,564 KB
testcase_11 AC 122 ms
55,680 KB
testcase_12 AC 122 ms
55,708 KB
testcase_13 AC 124 ms
55,596 KB
testcase_14 WA -
testcase_15 AC 122 ms
55,868 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 119 ms
56,432 KB
testcase_20 AC 119 ms
55,792 KB
testcase_21 AC 119 ms
55,812 KB
testcase_22 AC 120 ms
55,824 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 122 ms
55,748 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 117 ms
55,616 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;
                            }
                        }
                    }
                }
            }
            
            if(Stock.isEmpty()){
                System.out.println("-1");
            }else{
                Collections.sort(Stock);
                System.out.println(Stock.get(0));
            }
              
        }catch(Exception E){
            System.out.println("予期せぬエラーです");
        }
    }
}
0