結果
| 問題 |
No.227 簡単ポーカー
|
| コンテスト | |
| ユーザー |
nc_research
|
| 提出日時 | 2021-10-04 17:42:27 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,331 bytes |
| コンパイル時間 | 3,472 ms |
| コンパイル使用メモリ | 79,932 KB |
| 実行使用メモリ | 41,460 KB |
| 最終ジャッジ日時 | 2024-07-22 18:02:44 |
| 合計ジャッジ時間 | 5,764 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 4 |
ソースコード
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));
}
}
nc_research