結果
問題 | No.227 簡単ポーカー |
ユーザー | nc_research |
提出日時 | 2021-10-04 17:42:27 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,331 bytes |
コンパイル時間 | 3,877 ms |
コンパイル使用メモリ | 77,440 KB |
実行使用メモリ | 57,820 KB |
最終ジャッジ日時 | 2023-09-30 00:04:32 |
合計ジャッジ時間 | 6,526 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | AC | 105 ms
56,312 KB |
testcase_02 | AC | 103 ms
55,636 KB |
testcase_03 | AC | 103 ms
53,820 KB |
testcase_04 | AC | 107 ms
55,904 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 103 ms
55,900 KB |
testcase_08 | WA | - |
testcase_09 | AC | 103 ms
55,988 KB |
testcase_10 | AC | 106 ms
55,884 KB |
testcase_11 | AC | 101 ms
56,000 KB |
testcase_12 | AC | 120 ms
55,956 KB |
testcase_13 | AC | 106 ms
56,208 KB |
ソースコード
package com.mycompany.app; import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.HashMap; public class App { public static ArrayList<Integer> calcAndSortCountList(ArrayList<Integer> values){ // val -> count HashMap<Integer, Integer> count = new HashMap<Integer, Integer>(); for(Integer val : values){ if(count.containsKey(val)){ count.put(val, count.get(val) + 1); }else{ count.put(val,1); } } // カードの出現回数のみをリストに格納し,降順ソートする ArrayList<Integer> count_list = new ArrayList(count.values()); Collections.sort(count_list); Collections.reverse(count_list); return count_list; } public static String judgeHand(ArrayList<Integer> hand){ String full_house = "FULL HOUSE"; String three_card = "THREE CARD"; String two_pair = "TWO PAIR"; String one_pair = "ONE PAIR"; String no_hand = "NO_HAND"; ArrayList<Integer> count = calcAndSortCountList(hand); // 1. No Handsの判定 int max_freq_num = count.get(0); if((max_freq_num > 3) || (max_freq_num < 2)) return no_hand; // 2. 他の判定 int second_freq_num = count.get(1); if(max_freq_num == 3){ if(second_freq_num == 2) return full_house; return three_card; }else{ if(second_freq_num == 2) return two_pair; return one_pair; } } // strをseparatorで分割してArrayList<Integer>へ変換 public static ArrayList<Integer> splitToArrayList(String str, String separator){ ArrayList<Integer> ans = new ArrayList<Integer>(); String[] separated_str = str.split(" "); for(int i = 0; i < separated_str.length; i++){ ans.add(Integer.valueOf(separated_str[i])); } return ans; } public static void main( String[] args ) { Scanner scan = new Scanner(System.in); String first_line = scan.nextLine(); scan.close(); ArrayList<Integer> hands = splitToArrayList(first_line," "); System.out.println(judgeHand(hands)); } }