結果

問題 No.345 最小チワワ問題
ユーザー SagTokiSagToki
提出日時 2018-05-17 14:21:24
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,689 bytes
コンパイル時間 4,459 ms
コンパイル使用メモリ 75,968 KB
実行使用メモリ 57,732 KB
最終ジャッジ日時 2023-09-10 22:31:36
合計ジャッジ時間 9,879 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
56,012 KB
testcase_01 AC 121 ms
56,048 KB
testcase_02 AC 119 ms
55,776 KB
testcase_03 AC 119 ms
56,200 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 118 ms
56,264 KB
testcase_08 AC 120 ms
55,716 KB
testcase_09 AC 120 ms
56,300 KB
testcase_10 AC 121 ms
55,992 KB
testcase_11 AC 121 ms
55,884 KB
testcase_12 AC 122 ms
55,516 KB
testcase_13 AC 121 ms
55,772 KB
testcase_14 WA -
testcase_15 AC 121 ms
55,804 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 118 ms
55,992 KB
testcase_20 AC 119 ms
56,044 KB
testcase_21 AC 120 ms
55,752 KB
testcase_22 AC 123 ms
55,668 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 118 ms
55,664 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 119 ms
55,636 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 < S.length() ;i++){
                if(CS[i] == 'c'){
                    for(int j = i ; j < S.length() ; j++){
                        if(CS[j] == 'w'){
                            CountW++;
                            if(CountW == 2){
                                 Stock.add(j - i + 1);
                                 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