結果

問題 No.264 じゃんけん
ユーザー SaYaSaYa
提出日時 2015-11-06 00:14:05
言語 Java21
(openjdk 21)
結果
AC  
実行時間 130 ms / 5,000 ms
コード長 2,311 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 88,728 KB
実行使用メモリ 56,096 KB
最終ジャッジ日時 2023-10-11 14:11:47
合計ジャッジ時間 4,769 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
54,276 KB
testcase_01 AC 127 ms
54,048 KB
testcase_02 AC 127 ms
55,984 KB
testcase_03 AC 127 ms
53,988 KB
testcase_04 AC 127 ms
55,704 KB
testcase_05 AC 128 ms
55,944 KB
testcase_06 AC 130 ms
56,096 KB
testcase_07 AC 128 ms
53,868 KB
testcase_08 AC 127 ms
55,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Optional;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Hand myHand = Hand.of(Integer.parseInt(scanner.next())).get();
        Hand opponentHand = Hand.of(Integer.parseInt(scanner.next())).get();

        System.out.println(myHand.battle(opponentHand).toString());
    }

    private enum Hand {
        Rock(0) {
            @Override
            public BattleResult battle(Hand hand) {
                switch (hand) {
                    case Rock:
                        return BattleResult.Drew;
                    case Paper:
                        return BattleResult.Lost;
                    case Scissors:
                        return BattleResult.Won;
                    default:
                        return BattleResult.Unknown;
                }
            }
        },
        Scissors(1) {
            @Override
            public BattleResult battle(Hand hand) {
                switch (hand) {
                    case Rock:
                        return BattleResult.Lost;
                    case Paper:
                        return BattleResult.Won;
                    case Scissors:
                        return BattleResult.Drew;
                    default:
                        return BattleResult.Unknown;
                }
            }
        },
        Paper(2) {
            @Override
            public BattleResult battle(Hand hand) {
                switch (hand) {
                    case Rock:
                        return BattleResult.Won;
                    case Paper:
                        return BattleResult.Drew;
                    case Scissors:
                        return BattleResult.Lost;
                    default:
                        return BattleResult.Unknown;
                }
            }
        };

        private int num;

        Hand(int num) {
            this.num = num;
        }

        public static Optional<Hand> of(int num) {
            return Stream.of(values()).filter(e -> (e.num == num)).findFirst();
        }

        public abstract BattleResult battle(Hand hand);
    }

    private enum BattleResult {
        Won, Lost, Drew, Unknown
    }
}
0