結果

問題 No.227 簡単ポーカー
ユーザー nc_researchnc_research
提出日時 2021-10-04 17:43:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 114 ms / 5,000 ms
コード長 2,331 bytes
コンパイル時間 7,136 ms
コンパイル使用メモリ 81,956 KB
実行使用メモリ 56,256 KB
最終ジャッジ日時 2023-09-30 00:04:50
合計ジャッジ時間 5,368 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
55,620 KB
testcase_01 AC 110 ms
56,012 KB
testcase_02 AC 107 ms
56,256 KB
testcase_03 AC 103 ms
56,084 KB
testcase_04 AC 108 ms
55,884 KB
testcase_05 AC 106 ms
55,960 KB
testcase_06 AC 107 ms
56,052 KB
testcase_07 AC 109 ms
56,104 KB
testcase_08 AC 101 ms
55,912 KB
testcase_09 AC 105 ms
55,600 KB
testcase_10 AC 107 ms
55,780 KB
testcase_11 AC 112 ms
56,168 KB
testcase_12 AC 105 ms
55,848 KB
testcase_13 AC 114 ms
56,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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));
    }

}
0