結果

問題 No.345 最小チワワ問題
ユーザー TwinkleStar74
提出日時 2017-09-19 00:14:50
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 838 bytes
コンパイル時間 2,316 ms
コンパイル使用メモリ 74,092 KB
実行使用メモリ 52,232 KB
最終ジャッジ日時 2024-11-08 02:39:38
合計ジャッジ時間 4,647 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class No345 {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		int C =str.indexOf("c"); //cの位置
		int W1 = str.indexOf("w",C+1); //1つ目のwの位置
		int W2 = str.indexOf("w",W1+1); //2つ目のwの位置
		
		if (C !=-1 && W1 !=-1 && W2 != -1 &&  //cww全てが含まれ、且つCが一番小さい時
				C == Calc.min(C, W1,W2)){
			System.out.println( (W2 - C) + 1 );
		}
		else System.out.println(-1);
	}
	
public static class Calc {  //3つの数字の中で最小の物を返すメソッド(xだけ)
		public static int min(int x, int y, int z){
			if (x < y && x < z) return x;
			else return 0;
		}
	}
}
0