結果

問題 No.264 じゃんけん
ユーザー nihi9119nihi9119
提出日時 2017-05-10 20:22:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 2,563 bytes
コンパイル時間 3,914 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 49,532 KB
最終ジャッジ日時 2023-10-13 10:05:21
合計ジャッジ時間 5,174 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
49,384 KB
testcase_01 AC 42 ms
49,496 KB
testcase_02 AC 43 ms
49,268 KB
testcase_03 AC 43 ms
49,264 KB
testcase_04 AC 44 ms
49,280 KB
testcase_05 AC 42 ms
49,332 KB
testcase_06 AC 44 ms
49,532 KB
testcase_07 AC 44 ms
49,276 KB
testcase_08 AC 44 ms
49,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

/* 自分と相手がじゃんけんをする。
* じゃんけんの結果を標準出力に出力してください。
* 結果は、自分が勝ったら「Won」、自分が負けたら「Lost」、引き分けなら「Drew」を出力してください。
*/

public class Question_03_0510_01 {

	// 値の範囲
	static final int[] MAX = {2, 2};
	static final int[] MIN = {0, 0};

	// グー、チョキ、パー
	static final int GU = 0;
	static final int TYOKI = 1;
	static final int PA = 2;

	// 勝敗
	static final String KATI = "Won";
	static final String MAKE = "Lost";
	static final String AIKO = "Drew";

	public static void main(String[] args) {
		InputStreamReader re = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(re);
		int myself = 0; // 自分
		int opponent = 0; // 相手

		try {
			String[] inputString = br.readLine().split(" ");
			myself = Integer.parseInt(inputString[0]);
			opponent = Integer.parseInt(inputString[1]);

			// 有効値判定
			if (NumJudgment(myself, opponent, MAX, MIN)) {
				// じゃんけん
				System.out.println(ZyankenResult(myself, opponent));
			} else {
				System.out.println("0~2の数字を入れてください。");
			}
		} catch (NumberFormatException e) {
			System.out.println("数値または、整数の範囲内で入力して下さい。");
		} catch (IOException e) {
			System.out.println("エラーです");
		} finally {
			try {
				br.close();
			} catch (IOException e) {
				System.out.println("BufferedReaderクローズに失敗");
			}
		}
	}

	// 有効値判定メソッド
	static public boolean NumJudgment(int myself, int opponent, int[] MAX, int MIN[]) {
		Boolean result = false;
		if (myself <= MAX[0] && myself >= MIN[0] && opponent <= MAX[1] && opponent >= MIN[1]) {
			result = true;
		}
		return result;
	}

	// じゃんけん結果メソッド
	static public String ZyankenResult(int myself, int opponent) {
		String result = "";

		// 勝ち
		if ((myself == GU && opponent == TYOKI) || (myself == TYOKI && opponent == PA)
				|| (myself == PA && opponent == GU)) {
			result = KATI;
		}
		// 負け
		else if ((myself == GU && opponent == PA) || (myself == TYOKI && opponent == GU)
				|| (myself == PA && opponent == TYOKI)) {
			result = MAKE;
		}
		// あいこ
		else if ((myself == GU && opponent == GU) || (myself == TYOKI && opponent == TYOKI)
				|| (myself == PA && opponent == PA)) {
			result = AIKO;
		}

		return result;
	}
}
0