可读性拉满的一集
2024-10-09 12:54:36
发布于:浙江
44阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct card {
int num;
string col;
}a[10];
bool cmp_num(card x, card y) {return x.num == y.num ? x.col < y.col : x.num < y.num;};
bool cmp_col(card x, card y) {return x.col == y.col ? x.num < y.num : x.col < y.col;};
void sort_num() {sort(a, a + 5, cmp_num);};
void sort_col() {sort(a, a + 5, cmp_col);};
bool is_flush() {
sort_num();
for (int i = 1; i < 5; i++) if (a[i].num != a[i - 1].num + 1) return false;
return true;
}
bool same_col() {
sort_col();
return a[0].col == a[4].col;
}
bool is_hulu() {
sort_num();
if (a[0].num == a[2].num && a[3].num == a[4].num && a[0].num != a[4].num) return true;
if (a[0].num == a[1].num && a[2].num == a[4].num && a[0].num != a[4].num) return true;
return false;
}
int cnt_max() {
map<int,int> mp;
int mx = 0;
for (int i = 0; i < 5; i++) mp[a[i].num]++, mx = max(mx, mp[a[i].num]);
bool flag = false;
return mx;
}
bool is_two_pair() {
sort_num();
if (a[0].num == a[1].num && a[2].num == a[3].num) return true;
if (a[0].num == a[1].num && a[3].num == a[4].num) return true;
if (a[1].num == a[2].num && a[3].num == a[4].num) return true;
return false;
}
void solve() {
string x, y;
for (int i = 0; i < 5; i++) {
cin >> x >> a[i].col;
if (x == "A") a[i].num = 14;
else if (x == "K") a[i].num = 13;
else if (x == "Q") a[i].num = 12;
else if (x == "J") a[i].num = 11;
else if (x == "10") a[i].num = 10;
else a[i].num = x[0] - '0';
}
if (same_col() && is_flush()) {
if (a[0].num == 10) cout << "Royal Flush\n";
else cout << "Straight Flush\n";
}
else if (is_flush()) cout << "Straight\n";
else if (is_hulu()) cout << "Full House\n";
else if (cnt_max() == 5) cout << "High Card\n";
else if (cnt_max() == 4) cout << "Four of a Kind\n";
else if (cnt_max() == 3) cout << "Three of a Kind\n";
else if (is_two_pair()) cout << "Two Pairs\n";
else if (cnt_max() == 2) cout << "One Pair\n";
else cout << "High Card\n";
}
int main(){
int T;
cin >> T;
while (T--) solve();
return 0;
}
全部评论 1
老师太牛了!
2024-10-09 来自 美国
0
有帮助,赞一个