結果

問題 No.345 最小チワワ問題
ユーザー ohagi_1182
提出日時 2017-10-13 20:41:59
言語 Java
(openjdk 23)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 476 bytes
コンパイル時間 2,354 ms
コンパイル使用メモリ 75,208 KB
実行使用メモリ 41,676 KB
最終ジャッジ日時 2024-09-25 12:04:37
合計ジャッジ時間 7,347 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

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 ans = 1001001001;
		for(int i = 0 ; i < s.length() ; i++) {
			int w = 0;
			for(int j = i + 1 ; j < s.length() ; j++) {
				if(s.charAt(i) == 'c' && s.charAt(j) == 'w') {
					w++;
					if(w == 2) {
						ans = Math.min(ans, j - i + 1);
					}
				}
			}
		}
		System.out.println(ans == 1001001001 ? -1 : ans);
	}
}
0