結果

問題 No.486 3 Straight Win(3連勝)
ユーザー nihi9119nihi9119
提出日時 2017-06-09 09:38:31
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,315 bytes
コンパイル時間 3,949 ms
コンパイル使用メモリ 77,516 KB
実行使用メモリ 53,540 KB
最終ジャッジ日時 2023-10-23 20:33:58
合計ジャッジ時間 7,486 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,536 KB
testcase_01 WA -
testcase_02 AC 54 ms
53,528 KB
testcase_03 AC 53 ms
53,540 KB
testcase_04 AC 54 ms
52,500 KB
testcase_05 AC 54 ms
53,532 KB
testcase_06 AC 54 ms
53,540 KB
testcase_07 AC 53 ms
53,528 KB
testcase_08 WA -
testcase_09 AC 54 ms
53,528 KB
testcase_10 AC 55 ms
53,532 KB
testcase_11 AC 54 ms
53,540 KB
testcase_12 AC 53 ms
52,524 KB
testcase_13 AC 54 ms
53,532 KB
testcase_14 AC 56 ms
53,524 KB
testcase_15 AC 55 ms
53,540 KB
testcase_16 AC 53 ms
53,532 KB
testcase_17 AC 54 ms
53,532 KB
testcase_18 AC 52 ms
52,496 KB
testcase_19 WA -
testcase_20 AC 53 ms
53,536 KB
testcase_21 AC 53 ms
53,532 KB
testcase_22 AC 54 ms
52,480 KB
testcase_23 AC 54 ms
53,540 KB
testcase_24 AC 54 ms
52,528 KB
testcase_25 AC 54 ms
52,520 KB
testcase_26 AC 54 ms
53,536 KB
testcase_27 AC 54 ms
53,532 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連勝が早かった場合
				} else if (east == -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