結果

問題 No.227 簡単ポーカー
ユーザー yagi2yagi2
提出日時 2017-04-21 11:38:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 1,736 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 76,548 KB
実行使用メモリ 56,708 KB
最終ジャッジ日時 2023-09-27 10:51:07
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,876 KB
testcase_01 AC 111 ms
55,776 KB
testcase_02 AC 109 ms
56,124 KB
testcase_03 AC 109 ms
56,264 KB
testcase_04 AC 109 ms
56,708 KB
testcase_05 AC 110 ms
56,196 KB
testcase_06 AC 110 ms
56,416 KB
testcase_07 AC 111 ms
55,860 KB
testcase_08 AC 109 ms
56,344 KB
testcase_09 AC 110 ms
56,176 KB
testcase_10 AC 106 ms
56,028 KB
testcase_11 AC 108 ms
55,988 KB
testcase_12 AC 107 ms
55,656 KB
testcase_13 AC 114 ms
56,040 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 HAND");
        }
    }

    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