結果

問題 No.227 簡単ポーカー
ユーザー Hoboteru4484Hoboteru4484
提出日時 2019-12-03 01:00:07
言語 Java21
(openjdk 21)
結果
AC  
実行時間 125 ms / 5,000 ms
コード長 2,095 bytes
コンパイル時間 3,380 ms
コンパイル使用メモリ 76,372 KB
実行使用メモリ 56,160 KB
最終ジャッジ日時 2023-08-16 14:12:55
合計ジャッジ時間 6,048 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,160 KB
testcase_01 AC 121 ms
55,720 KB
testcase_02 AC 122 ms
55,700 KB
testcase_03 AC 121 ms
55,836 KB
testcase_04 AC 122 ms
56,040 KB
testcase_05 AC 123 ms
55,720 KB
testcase_06 AC 119 ms
55,924 KB
testcase_07 AC 123 ms
55,444 KB
testcase_08 AC 120 ms
55,732 KB
testcase_09 AC 121 ms
56,140 KB
testcase_10 AC 125 ms
55,800 KB
testcase_11 AC 124 ms
55,648 KB
testcase_12 AC 123 ms
55,644 KB
testcase_13 AC 119 ms
55,644 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Arrays;
import java.util.HashMap;

public class No227 {
  public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
    HashMap<String,Integer> cardMap = new HashMap<String,Integer>();
    
    for(int i =0;i < 5;i++){
      int card = sc.nextInt();
      if(cardMap.containsKey(Integer.toString(card))){
        cardMap.put(Integer.toString(card),cardMap.get(Integer.toString(card))+1);
      }else{
        cardMap.put(Integer.toString(card),1);
      }
    }
    sc.close();
    
    No227 obj =new No227();
    String hand = obj.judgeHand(cardMap);
    System.out.println(hand);
  }
  
  private String judgeHand(HashMap<String,Integer> cardMap){
    String FULL_HOUSE = "FULL HOUSE";//ある数をちょうど3つと、別の数をちょうど2つ含む。
    String THREE_CARD = "THREE CARD";//ある数をちょうど3つ含む。
    String TWO_PAIR = "TWO PAIR";//ある数をちょうど2つと、別の数をちょうど2つ含む。
    String ONE_PAIR = "ONE PAIR";//ある数をちょうど2つ含む。
    String NO_HAND = "NO HAND";//上記以外

    // for (String key : cardMap.keySet()){
    //   System.out.println(key + ":" + cardMap.get(key));
    // }
    HashMap<String,Integer> handMap =new HashMap<String,Integer>();
    for (String cardMapKey : cardMap.keySet()){
      String handMapKey = Integer.toString(cardMap.get(cardMapKey));
      if(cardMap.get(cardMapKey) >= 2){
        if (handMap.containsKey(handMapKey)){
          handMap.put(handMapKey,handMap.get(handMapKey)+1);
        }else{
          handMap.put(handMapKey,1);
        }
      }
    }

    if(handMap.size() == 0){
      return NO_HAND;
    }else{
      if(handMap.containsKey("3") && handMap.containsKey("2")){
        return FULL_HOUSE;
      }else if(handMap.containsKey("3")){
        return THREE_CARD;
      }else if(handMap.containsKey("2")){
        if (handMap.get("2") == 2){
          return TWO_PAIR;
        }else {
          return ONE_PAIR;
        }
      }else{
        return NO_HAND;
      }
    }
  }
}
0