結果

問題 No.227 簡単ポーカー
ユーザー yagi2yagi2
提出日時 2017-04-21 11:38:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,736 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 76,340 KB
実行使用メモリ 57,928 KB
最終ジャッジ日時 2023-09-27 10:50:50
合計ジャッジ時間 5,033 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 122 ms
56,040 KB
testcase_02 AC 122 ms
56,040 KB
testcase_03 AC 123 ms
55,632 KB
testcase_04 AC 119 ms
57,928 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 121 ms
55,920 KB
testcase_08 WA -
testcase_09 AC 122 ms
55,964 KB
testcase_10 AC 126 ms
55,648 KB
testcase_11 AC 120 ms
55,636 KB
testcase_12 AC 129 ms
55,856 KB
testcase_13 AC 120 ms
55,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        List<Integer> cards = new ArrayList<>();

        for (int i = 0; i < 5; i++) {
            cards.add(Integer.parseInt(sc.next()));
        }

        if (isFullHouse(cards)) {
            System.out.println("FULL HOUSE");
        } else if (isThreeCard(cards)) {
            System.out.println("THREE CARD");
        } else if (isTwoPair(cards)) {
            System.out.println("TWO PAIR");
        } else if (isOnePair(cards)) {
            System.out.println("ONE PAIR");
        } else {
            System.out.println("NO HANDS");
        }
    }

    private static boolean isFullHouse(List<Integer> cards) {
        Map<Integer, Integer> match = calcCards(cards);
        return match.size() == 2 && match.containsValue(3);
    }

    private static boolean isThreeCard(List<Integer> cards) {
        Map<Integer, Integer> match = calcCards(cards);
        return match.containsValue(3);
    }

    private static boolean isTwoPair(List<Integer> cards) {
        Map<Integer, Integer> match = calcCards(cards);
        return match.size() == 3 && !match.containsValue(3);
    }

    private static boolean isOnePair(List<Integer> cards) {
        Map<Integer, Integer> match = calcCards(cards);
        return match.size() == 4;
    }

    private static Map<Integer, Integer> calcCards(List<Integer> cards) {
        Map<Integer, Integer> match = new HashMap<>();

        for (Integer card : cards) {
            if (!match.containsKey(card)) {
                match.put(card, 0);
            }
            match.put(card, match.get(card) + 1);
        }

        return match;
    }
}
0