Advertisement
Naxocist

Poker

Apr 3rd, 2022
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endll '\n'
  3. using namespace std;
  4.  
  5. struct card {
  6.     int val; string suit;
  7.     card(int v, string s) : val(v), suit(s) {}
  8.     bool operator< (const card &other) const{
  9.         return val < other.val;
  10.     }
  11. };
  12.  
  13. unordered_map<char, int> um = {{'J', 11}, {'Q', 12}, {'K', 13}, {'A', 14}}, tmp;
  14.  
  15. int convert(string val){
  16.     int num = atoi(val.c_str());
  17.     if(num) return num;
  18.  
  19.     return um[val[0]];
  20. }
  21.  
  22.  
  23. bool is_flush(multiset<card> d){
  24.     set<string> chk;
  25.     for(auto x : d) chk.insert(x.suit);
  26.     return (chk.size() == 1);
  27. }
  28.  
  29.  
  30. bool is_straight(multiset<card> d){
  31.     int chkV = (*(d.begin())).val;
  32.     for(auto x : d){
  33.         if(x.val != chkV) return false;
  34.         chkV++;
  35.     }
  36.     return true;
  37. }
  38.  
  39. bool royalFlush(multiset<card> d){
  40.     if(!is_flush(d)) return false;
  41.  
  42.     int chkV = 10;
  43.     for(auto x : d){
  44.         if(x.val != chkV) return false;
  45.         chkV++;
  46.     }
  47.     return true;
  48. }
  49.  
  50.  
  51. bool is_kind(multiset<card> d, int chk){
  52.  
  53.     for(auto x : tmp) if(x.second == chk) return true;
  54.     return false;
  55. }
  56.  
  57. bool fullHouse(multiset<card> d){
  58.  
  59.     if(tmp.size() > 2) return false;
  60.     bool chk2 = false, chk3 = false;
  61.     for(auto x : tmp){
  62.         if(x.second == 2) chk2 = true;
  63.         if(x.second == 3) chk3 = true;
  64.     }
  65.     if(chk2 && chk3) return true;
  66.     return false;
  67.  
  68. }
  69.  
  70. bool is_pair(multiset<card> deck, int chk){
  71.  
  72.     int cnt = 0;
  73.     for(auto x : tmp) if(x.second == 2) cnt++;
  74.  
  75.     if(cnt == chk) return true;
  76.     return false;
  77. }
  78.  
  79.  
  80. int main(){
  81.  
  82.     int n; scanf("%d", &n);
  83.     multiset<card> deck;
  84.     while(n--){
  85.         for(int i=0; i<5; ++i){
  86.             string suit, val;
  87.             cin >> val >> suit;
  88.             deck.insert(card(convert(val), suit));
  89.         }
  90.  
  91.         for(auto x : deck) tmp[x.val] += 1;
  92.  
  93.         if(royalFlush(deck)) printf("Royal Flush\n");
  94.         else if(is_straight(deck) && is_flush(deck)) printf("Straight Flush\n");
  95.         else if(is_kind(deck, 4)) printf("Four Of A Kind\n");
  96.         else if(fullHouse(deck)) printf("Full House\n");
  97.         else if(is_flush(deck)) printf("Flush\n");
  98.         else if(is_straight(deck)) printf("Straight\n");
  99.         else if(is_kind(deck, 3)) printf("Three Of A Kind\n");
  100.         else if(is_pair(deck, 2)) printf("Two Pair\n");
  101.         else if(is_pair(deck, 1)) printf("One Pair\n");
  102.         else printf("High Card\n");
  103.         deck.clear();
  104.         tmp.clear();
  105.     }
  106.     return 0;
  107. }
  108. /*
  109. 1
  110. A diamond
  111. 2 club
  112. 3 diamond
  113. 4 spade
  114. 5 club
  115. */
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement