結果
| 問題 | No.264 じゃんけん |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-05-15 01:49:01 |
| 言語 | Java (openjdk 25.0.1) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 5,000 ms |
| コード長 | 2,168 bytes |
| 記録 | |
| コンパイル時間 | 3,538 ms |
| コンパイル使用メモリ | 78,012 KB |
| 実行使用メモリ | 50,268 KB |
| 最終ジャッジ日時 | 2024-09-16 05:56:28 |
| 合計ジャッジ時間 | 4,497 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 |
ソースコード
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;
}
}