結果

問題 No.264 じゃんけん
ユーザー nihi9119nihi9119
提出日時 2017-05-15 01:49:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 41 ms / 5,000 ms
コード長 2,168 bytes
コンパイル時間 2,990 ms
コンパイル使用メモリ 75,800 KB
実行使用メモリ 49,432 KB
最終ジャッジ日時 2023-10-14 11:04:25
合計ジャッジ時間 3,971 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
49,432 KB
testcase_01 AC 41 ms
49,368 KB
testcase_02 AC 41 ms
49,392 KB
testcase_03 AC 40 ms
47,444 KB
testcase_04 AC 41 ms
49,388 KB
testcase_05 AC 40 ms
49,292 KB
testcase_06 AC 40 ms
49,424 KB
testcase_07 AC 40 ms
49,332 KB
testcase_08 AC 41 ms
49,420 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

public class Question_03_0510_02 {

	// 値の範囲
	static final int MAX = 2;
	static final int MIN = 0;

	// グー、チョキ、パー
	// GU = 0 TYOKI = 1 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 {
				re.close();
				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 >= MIN && myself <= MAX) {
			if (opponent >= MIN && opponent <= MAX) {
				result = true;
			}
		}
		return result;
	}

	// じゃんけん結果メソッド
	static private String ZyankenResult(int myself, int opponent) {
		String result = "";
		if (myself == opponent) {
			result = AIKO;
		} else if ((myself + 1) % 3 == opponent) {
			result = KATI;

		} else {
			result = MAKE;
		}
		return result;
	}
}
0