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 calcAndSortCountList(ArrayList values){ // val -> count HashMap count = new HashMap(); for(Integer val : values){ if(count.containsKey(val)){ count.put(val, count.get(val) + 1); }else{ count.put(val,1); } } // カードの出現回数のみをリストに格納し,降順ソートする ArrayList count_list = new ArrayList(count.values()); Collections.sort(count_list); Collections.reverse(count_list); return count_list; } public static String judgeHand(ArrayList 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 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へ変換 public static ArrayList splitToArrayList(String str, String separator){ ArrayList ans = new ArrayList(); 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 hands = splitToArrayList(first_line," "); System.out.println(judgeHand(hands)); } }