結果

問題 No.345 最小チワワ問題
ユーザー mits58mits58
提出日時 2016-07-02 18:27:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 4,583 ms
コンパイル使用メモリ 74,308 KB
実行使用メモリ 57,680 KB
最終ジャッジ日時 2023-10-26 03:58:39
合計ジャッジ時間 7,489 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
57,556 KB
testcase_01 AC 126 ms
57,460 KB
testcase_02 AC 126 ms
57,368 KB
testcase_03 AC 128 ms
57,496 KB
testcase_04 AC 125 ms
57,492 KB
testcase_05 AC 121 ms
57,240 KB
testcase_06 AC 126 ms
57,500 KB
testcase_07 AC 128 ms
57,544 KB
testcase_08 AC 129 ms
57,516 KB
testcase_09 AC 131 ms
57,504 KB
testcase_10 AC 127 ms
57,408 KB
testcase_11 AC 126 ms
57,504 KB
testcase_12 AC 128 ms
57,584 KB
testcase_13 AC 129 ms
57,680 KB
testcase_14 AC 130 ms
57,520 KB
testcase_15 AC 133 ms
57,448 KB
testcase_16 AC 128 ms
57,508 KB
testcase_17 AC 129 ms
57,452 KB
testcase_18 AC 128 ms
57,608 KB
testcase_19 AC 127 ms
57,612 KB
testcase_20 AC 124 ms
57,468 KB
testcase_21 AC 126 ms
57,556 KB
testcase_22 AC 130 ms
57,540 KB
testcase_23 AC 129 ms
57,488 KB
testcase_24 AC 130 ms
57,468 KB
testcase_25 AC 125 ms
57,544 KB
testcase_26 AC 126 ms
57,452 KB
testcase_27 AC 125 ms
57,624 KB
testcase_28 AC 125 ms
55,552 KB
testcase_29 AC 128 ms
57,484 KB
testcase_30 AC 128 ms
57,540 KB
testcase_31 AC 127 ms
55,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			String s=sc.next();
			int ans=Integer.MAX_VALUE;
			for(int i=0;i<s.length();i++){
				if(s.charAt(i)=='c'){
					int l=1; int c=0;
					for(int j=i;j<s.length();j++){
						if(s.charAt(j)=='w') c++;
						if(c==2){
							l=j-i+1;
							break;
						}
					}
					if(l>=3) ans=Math.min(ans,l);
				}
			}
			if(ans==Integer.MAX_VALUE) System.out.println(-1);
			else System.out.println(ans);
		}
	}
}
0