結果

問題 No.486 3 Straight Win(3連勝)
ユーザー nihi9119nihi9119
提出日時 2017-06-09 09:42:54
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 2,366 bytes
コンパイル時間 3,777 ms
コンパイル使用メモリ 73,952 KB
実行使用メモリ 33,900 KB
最終ジャッジ日時 2023-09-08 11:10:05
合計ジャッジ時間 6,290 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
33,468 KB
testcase_01 AC 37 ms
33,608 KB
testcase_02 AC 37 ms
33,400 KB
testcase_03 AC 38 ms
33,444 KB
testcase_04 AC 39 ms
33,500 KB
testcase_05 AC 40 ms
33,404 KB
testcase_06 AC 39 ms
33,508 KB
testcase_07 AC 39 ms
33,388 KB
testcase_08 AC 45 ms
33,424 KB
testcase_09 AC 38 ms
33,488 KB
testcase_10 AC 38 ms
33,392 KB
testcase_11 AC 37 ms
33,412 KB
testcase_12 AC 46 ms
33,464 KB
testcase_13 AC 38 ms
33,900 KB
testcase_14 AC 37 ms
33,448 KB
testcase_15 AC 37 ms
33,388 KB
testcase_16 AC 38 ms
33,472 KB
testcase_17 AC 37 ms
33,452 KB
testcase_18 AC 37 ms
33,412 KB
testcase_19 AC 38 ms
33,500 KB
testcase_20 AC 38 ms
33,424 KB
testcase_21 AC 38 ms
33,432 KB
testcase_22 AC 37 ms
33,464 KB
testcase_23 AC 37 ms
33,444 KB
testcase_24 AC 37 ms
33,244 KB
testcase_25 AC 38 ms
33,320 KB
testcase_26 AC 38 ms
33,488 KB
testcase_27 AC 37 ms
33,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package test6;

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

/**
 * No.486 3 Straight Win(3連勝) http://yukicoder.me/problems/no/486
 * 東軍と西軍はあるゲームで勝負しています。
 * そのゲームは東軍と西軍のどちらか一方が必ず勝ちもう一方は必ず負けます。
 * 両軍はそのゲームを何度か繰り返し、先に3連勝した方をこのゲームの最終的な勝者にしようと取り決めました。
 */

public class Question_17_0609 {

	static final int MIN = 1;
	static final int MAX = 100;
	static final String EAST_WIN = "OOO"; //東軍の勝利
	static final String WEST_WIN = "XXX"; //西軍の勝利

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);

		try {
			String input = br.readLine();

			if (LengthJudg(input, MIN, MAX)) {

				//最初に三連勝した場所を数える
				int east = input.indexOf(EAST_WIN);
				int west = input.indexOf(WEST_WIN);

				String result = "";
				//勝利判定
				//両者とも3連勝していない
				if (east == west) {
					result = "NA";
				//東軍が3連勝していない、または
				//西軍が3連勝し、かつ西軍の方が3連勝が早かった場合
				} else if (east == -1 || (west != -1 && Math.min(east, west) == west)) {
					result = "West";
				} else {
					result = "East";
				}
				System.out.println(result);

			} else {
				System.out.println("入力文字の長さが有効範囲外です");
			}

		} catch (NumberFormatException e) {
			System.out.println("数字を入力して下さい。");
		} catch (IOException e) {
			System.out.println("エラーが発生しました。");
		} finally {
			try {
				re.close();
				br.close();
			} catch (IOException e) {
				System.out.println("InputStreamReader、BufferedReaderクローズ中にエラーが発生しました");
			}
		}
	}

	/**
	 * 有効値判定
	 * @param input 判定するもの
	 * @param max 最大値
	 * @param min 最小値
	 * @return 範囲内ならtrue,範囲外ならfalseを返す
	 */
	private static boolean LengthJudg(String input, int min, int max) {
		Boolean result = false;
		if (min <= input.length() && input.length() <= max) {
			result = true;
		}
		return result;
	}
}
0