結果

問題 No.345 最小チワワ問題
ユーザー GrenacheGrenache
提出日時 2016-02-26 22:26:50
言語 Java
(openjdk 23)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 793 bytes
コンパイル時間 3,389 ms
コンパイル使用メモリ 75,168 KB
実行使用メモリ 41,476 KB
最終ジャッジ日時 2024-09-25 11:23:42
合計ジャッジ時間 8,469 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;


public class Main_yukicoder345 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        char[] s = sc.next().toCharArray();
        int n = s.length;

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
        	if (s[i] != 'c') {
        		continue;
        	} else {
        		int cnt = 0;
        		int j;
        		for (j = i + 1; j < n && cnt < 2; j++) {
        			if (s[j] == 'w') {
        				cnt++;
        			}
        		}

        		if (cnt == 2) {
        			min = Math.min(min, j - i);
        		}
        	}
        }

        if (min == Integer.MAX_VALUE) {
        	System.out.println(-1);
        } else {
        	System.out.println(min);
        }

        sc.close();
    }
}
0