H. Texas hold'em Poker
思路:根据每个牌型分等级,然后排序按照等级优先,最大值次之,次大值,最后比较剩下值的和。
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 5; 4 struct node{ 5 string name; 6 int id = 0; 7 int sum = 0; 8 int maxx = 0; 9 int maxx2 = 0; 10 }; 11 node a[maxn]; 12 bool cmp(const node &a, const node &b) 13 { 14 if(a.id != b.id) return a.id > b.id; 15 if(a.maxx != b.maxx) return a.maxx > b.maxx; 16 if(a.maxx2 != b.maxx2) return a.maxx2 > b.maxx2; 17 if(a.sum != b.sum) return a.sum > b.sum; 18 return a.name < b.name; 19 } 20 int v[5]; 21 int main() 22 { 23 std::ios::sync_with_stdio(false); 24 int n; 25 string s; 26 cin >> n; 27 for(int i = 0;i < n;i++) 28 { 29 cin >> a[i].name >> s; 30 int cnt = 0; 31 for(int j = 0;j < s.size();j++) 32 { 33 if(s[j] == '0') continue; 34 else if(s[j] == '1') v[cnt++] = 10; 35 else if(s[j] == 'A') v[cnt++] = 1; 36 else if(s[j] == 'J') v[cnt++] = 11; 37 else if(s[j] == 'Q') v[cnt++] = 12; 38 else if(s[j] == 'K') v[cnt++] = 13; 39 else v[cnt++] = s[j] - '0'; 40 } 41 sort(v, v + 5); 42 int vis[13] = {0}; 43 for(int j= 0;j < 5;j++) 44 { 45 a[i].sum += v[j]; 46 vis[v[j]]++; 47 } 48 if(v[0] == 1 && v[1] == 10 && v[2] == 11 && v[3] == 12 && v[4] == 13){ 49 a[i].id = 7;continue; 50 } 51 if(v[2] == v[1] + 1 && v[2] == v[0] + 2 && v[2] == v[3] - 1 && v[2] == v[4] - 2){ 52 a[i].id = 6; 53 a[i].maxx = v[4]; 54 continue; 55 } 56 int two = 0, three = 0; 57 int t = 0, tt = 0, ttt; 58 for(int j = 1;j <= 13;j++) 59 { 60 if(vis[j] == 4){ 61 a[i].id = 5; 62 a[i].maxx = j; 63 a[i].sum -= j * 4; 64 break; 65 } 66 if(vis[j] == 3) three ++, ttt = j ; 67 if(vis[j] == 2){ 68 two++; 69 if(!t) t = j; 70 else tt = j; 71 } 72 } 73 if(three == 1 && two == 1) 74 { 75 a[i].id = 4; 76 a[i].maxx = ttt; 77 a[i].maxx2 = t; 78 continue; 79 } 80 if(three == 1) 81 { 82 a[i].id = 3; 83 a[i].maxx = ttt; 84 a[i].sum -= 3 * ttt; 85 continue; 86 } 87 if(two == 2) 88 { 89 a[i].id = 2; 90 a[i].maxx = max(t,tt); 91 a[i].maxx2 = min(t,tt); 92 a[i].sum -= (t + tt) * 2; 93 } 94 if(two){ 95 a[i].id = 1; 96 a[i].maxx = t; 97 a[i].sum -= 2*t; 98 } 99 } 100 sort(a, a + n, cmp); 101 for(int i = 0;i < n;i++) 102 { 103 cout << a[i].name << endl; 104 //cout << " " << a[i].id << " " << a[i].maxx << " " << a[i].maxx2 << " " << a[i].sum << endl; 105 } 106 return 0; 107 }