結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182ohagi_1182
提出日時 2017-10-13 18:54:03
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 590 bytes
コンパイル時間 1,861 ms
コンパイル使用メモリ 71,352 KB
実行使用メモリ 56,264 KB
最終ジャッジ日時 2023-08-11 00:24:12
合計ジャッジ時間 6,623 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
55,836 KB
testcase_01 AC 111 ms
55,460 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 111 ms
55,680 KB
testcase_05 AC 113 ms
56,120 KB
testcase_06 AC 112 ms
55,828 KB
testcase_07 AC 110 ms
55,900 KB
testcase_08 AC 112 ms
56,156 KB
testcase_09 AC 114 ms
55,592 KB
testcase_10 AC 115 ms
55,420 KB
testcase_11 AC 114 ms
55,932 KB
testcase_12 AC 114 ms
56,024 KB
testcase_13 AC 114 ms
55,680 KB
testcase_14 AC 110 ms
56,112 KB
testcase_15 AC 115 ms
55,584 KB
testcase_16 AC 112 ms
55,728 KB
testcase_17 WA -
testcase_18 AC 110 ms
56,112 KB
testcase_19 AC 117 ms
55,856 KB
testcase_20 AC 113 ms
55,864 KB
testcase_21 AC 111 ms
55,676 KB
testcase_22 AC 116 ms
55,888 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 111 ms
55,984 KB
testcase_29 AC 108 ms
55,704 KB
testcase_30 AC 109 ms
55,816 KB
testcase_31 AC 109 ms
55,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int c = 0; int w = 0; int indexC = 0; int indexW = 0; int ans = 1001001001;
		for(int i = 0 ; i < s.length() ; i++) {
			if(s.charAt(i) == 'c') {
				c = 1;
				w = 0;
				indexC = i;
			} else if(s.charAt(i) == 'w') {
				w++;
				if(c == 1 && w == 2) {
					indexW = i;
					ans = Math.min(ans, indexW - indexC + 1);
				}
			}
		}
		if(ans != 1001001001) {
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}
}
0