結果
| 問題 |
No.264 じゃんけん
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-10 20:22:33 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 52 ms / 5,000 ms |
| コード長 | 2,563 bytes |
| コンパイル時間 | 3,688 ms |
| コンパイル使用メモリ | 77,212 KB |
| 実行使用メモリ | 36,928 KB |
| 最終ジャッジ日時 | 2024-09-15 07:11:16 |
| 合計ジャッジ時間 | 4,692 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 |
ソースコード
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;
}
}