The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold'em Poker

题目链接:https://nanti.jisuanke.com/t/41408

题目意思很简单,就是个模拟过程。


  1 #include 
  2 #include 
  3 #include 
  4 #include 
  5 #include 
  6 #define rep(i,j,k) for(int i = (j); i <= (k); ++i)
  7 #define per(i,j,k) for(int i = (j); i >= (k); --i)
  8 #define rep__(i,j,k) for(int i = (j); i < (k); ++i)
  9 #define per__(i,j,k) for(int i = (j); i > (k); --i)
 10 #define inf 1e9
 11 using namespace std;
 12 typedef long long LL;
 13 const int N = (int)1e5 + 10;
 14 
 15 // map mp;
 16 struct node{
 17     char name[20];
 18     int card[20];
 19     bool pair;
 20     int rank_1,rank_2;
 21     int sum;
 22 
 23     void fun(char* tmp){
 24         rep__(i,0,20) card[i] = 0;
 25         rank_1 = rank_2 = 0;
 26         pair = false;
 27         sum = 0;
 28         int i = 0;
 29         while(tmp[i] != '\0'){
 30             if(tmp[i] == '1'){ //10
 31                 ++card[10];
 32                 i += 2;
 33                 sum += 10;//得出卡的总价值
 34             }
 35             else{
 36                 int k = 0;
 37                 if(tmp[i] >= '2' && tmp[i] <= '9') k = tmp[i] - '1' + 1;
 38                 else if(tmp[i] == 'A') k = 1;
 39                 else if(tmp[i] == 'J') k = 11;
 40                 else if(tmp[i] == 'Q') k = 12;
 41                 else if(tmp[i] == 'K') k = 13;
 42                 ++card[k];
 43                 ++i;
 44                 sum += k;//得出卡的总价值
 45             }
 46         }
 47     }
 48 
 49     void rank(){
 50         bool com = true;//没有任何的等级
 51         //最大的顺子
 52         if(card[10] && card[11] && card[12] && card[13] && card[1]){
 53             rank_1 = 10;
 54             com = false;
 55         }
 56         else {
 57             rep(i,1,13){
 58                 if(card[i] == 4) rank_1 = 8,sum += (-4*i + i*100),com = false;
 59                 else if(card[i] == 3){
 60                     //rank_1 == 0 ? rank_1 = 7 : rank_1 = 7,rank_2 = 1;
 61                     if(rank_1 == 0) rank_1 = 7;
 62                     else rank_1 = 7,rank_2 = 1;
 63                     sum += (-3*i + i*10000);
 64                     com = false;
 65                 }
 66                 else if(card[i] == 2){
 67                     if(!pair){
 68                         rank_1 == 0 ? rank_1 = 1 : rank_2 = 1;
 69                         sum += (-2*i + i*100);
 70                         pair = 1;
 71                         com = false;
 72                     }
 73                     else{
 74                         rank_2 = 1;
 75                         sum += (-2*i + i*10000);
 76                     }
 77                 }
 78             }
 79         }
 80         //都不相同
 81         if(com){
 82             rep(i,1,13){
 83                 if(i + 4 > 13) break;
 84                 if(card[i] && card[i + 1] && card[i + 2] && card[i + 3] && card[i + 4]){
 85                     rank_1 = 9;
 86                     break;
 87                 }
 88             }
 89         }
 90     }
 91 
 92     bool friend operator<(const node& a,const node& b){
 93         if(a.rank_1 != b.rank_1) return a.rank_1 > b.rank_1;
 94         else{
 95             if(a.rank_2 != b.rank_2) return a.rank_2 > b.rank_2;
 96             else{
 97                 if(a.sum != b.sum) return a.sum > b.sum;
 98                 else return strcmp(a.name,b.name) < 0 ? 1 : 0;
 99             }
100         }
101     }
102 }stu[N];
103 
104 int main(){
105 
106     ios::sync_with_stdio(false);
107     cin.tie(0);
108     // mp['A'] = 1; mp['2'] = 2; mp['3'] = 3; mp['4'] = 4; mp['5'] = 5; mp['6'] = 6;
109     // mp['7'] = 7; mp['8'] = 8; mp['9'] = 9; mp['J'] = 11; mp['Q'] = 12; mp['K'] = 13;
110     int n;
111     char tmp[20];
112     while(cin >> n){
113         
114         rep(i,1,n){
115             cin >> stu[i].name >> tmp;
116             stu[i].fun(tmp);//装换成卡片
117             stu[i].rank();//等级
118         }
119     
120         sort(stu + 1,stu + 1 + n);
121 
122         rep(i,1,n) cout << stu[i].name << endl;
123     }
124 
125 //    getchar();getchar();
126     return 0;
127 }
128 //  << ' ' << stu[i].rank_1 << ' '  << stu[i].rank_2  << ' ' << stu[i].sum 
129 
130 /*
131 
132 7
133 AQ A2345
134 AW 58976
135 AS 5A397
136 AP AAA99
137 AL 222AA
138 AG AA229
139 AU 1010A23
140 */

 

你可能感兴趣的:(The Preliminary Contest for ICPC Asia Shenyang 2019 H. Texas hold'em Poker)