結果

問題 No.345 最小チワワ問題
ユーザー nglkrianbrjfnglkrianbrjf
提出日時 2016-02-26 22:37:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 813 bytes
コンパイル時間 3,340 ms
コンパイル使用メモリ 74,204 KB
実行使用メモリ 53,496 KB
最終ジャッジ日時 2023-10-24 05:06:12
合計ジャッジ時間 7,162 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,484 KB
testcase_01 AC 55 ms
53,472 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 54 ms
53,480 KB
testcase_05 AC 54 ms
53,476 KB
testcase_06 AC 53 ms
53,476 KB
testcase_07 AC 53 ms
53,476 KB
testcase_08 AC 54 ms
53,484 KB
testcase_09 AC 54 ms
53,476 KB
testcase_10 AC 54 ms
53,484 KB
testcase_11 AC 54 ms
53,476 KB
testcase_12 AC 54 ms
53,476 KB
testcase_13 WA -
testcase_14 AC 55 ms
53,496 KB
testcase_15 AC 53 ms
53,484 KB
testcase_16 AC 53 ms
53,472 KB
testcase_17 WA -
testcase_18 AC 54 ms
53,484 KB
testcase_19 AC 54 ms
53,484 KB
testcase_20 AC 54 ms
53,444 KB
testcase_21 AC 53 ms
53,488 KB
testcase_22 AC 54 ms
53,484 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 55 ms
53,476 KB
testcase_30 AC 54 ms
53,480 KB
testcase_31 AC 54 ms
53,484 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class QuestionA {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;

		try{
			line = in.readLine();
		}catch(IOException e){
			line = "";
		}

		int min = line.length();
		int c = 0;//直前のcの位置
		int w = 0;//直前のwの位置
		boolean check = false;

		for(int i = 0; i < line.length(); i++){
			if(line.charAt(i) == 'c')
				c = i;
			if(line.charAt(i) == 'w'){
				if(c < w){
					check = true;
					if(min > i - c + 1)
						min = i - c + 1;
				}
				else
					w = i;
			}
		}

		if(check) System.out.println(min);
		else System.out.println("-1");
	}

}
0