結果
問題 |
No.227 簡単ポーカー
|
ユーザー |
|
提出日時 | 2017-04-21 11:38:53 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 125 ms / 5,000 ms |
コード長 | 1,736 bytes |
コンパイル時間 | 2,152 ms |
コンパイル使用メモリ | 79,380 KB |
実行使用メモリ | 41,552 KB |
最終ジャッジ日時 | 2024-07-20 05:00:52 |
合計ジャッジ時間 | 4,387 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 |
ソースコード
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; } }