bush gemer我的代码怎么这么长啊
2024-10-14 20:09:20
发布于:广东
15阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct node{
int a;
string b;
}op[10];
bool cmp(node z,node k){
return z.a < k.a;
}
int bflush(){
string z = "";
for(int i = 0;i < 5;i ++){
if(z != "" and op[i].b != z){
return 0;
}
z = op[i].b;
}
bool flag = 1;
for(int i = 0;i < 5;i ++){
if(op[i].a != 9 + i){
flag = 0;
}
}
if(flag == 1){
return 100;
}
flag = 1;
int tmp = 0;
for(int i = 0;i < 5;i ++){
bool cflag = 1;
if(op[i - 1].a == 13 and op[i].a == 1){
cflag = 0;
}
if(tmp != 0 and op[i].a != tmp + 1 and cflag == 1){
return 0;
} else {
tmp = op[i].a;
}
}
return 50;
}
int ttt(){
int tmp = 0;
for(int i = 0;i < 5;i ++){
bool cflag = 1;
if(op[i - 1].a == 13 and op[i].a == 1){
cflag = 0;
}
if(tmp != 0 and op[i].a != tmp + 1 and cflag == 1){
return 0;
} else {
tmp = op[i].a;
}
}
return 30;
}
int apair(){
int mm[20] = {};
for(int i = 0;i < 5;i ++){
mm[op[i].a] ++;
}
int cnt = 0;
int cnta = 0;
int cntb = 0;
for(int i = 0;i < 20;i ++){
if(mm[i] == 2){
cnt ++;
}
if(mm[i] == 3){
cnta ++;
}
if(mm[i] == 4){
cntb ++;
}
}
if(cnt == 1 and cnta == 0){
return 2;
} else if(cnta == 1 and cnt == 0){
return 3;
} else if(cntb == 1){
return 4;
} else if(cnt == 2){
return 5;
} else if(cnt == 1 and cnta == 1){
return 6;
} else {
return 0;
}
}
int main(){
map<string,int> mp;
mp["2"] = 1;
mp["3"] = 2;
mp["4"] = 3;
mp["5"] = 4;
mp["6"] = 5;
mp["7"] = 6;
mp["8"] = 7;
mp["9"] = 8;
mp["10"] = 9;
mp["J"] = 10;
mp["Q"] = 11;
mp["K"] = 12;
mp["A"] = 13;
int t;
cin >> t;
while(t --){
for(int i = 0;i < 5;i ++){
string r;
cin >> r;
op[i].a = mp[r];
cin >> op[i].b;
}
sort(op,op + 5,cmp);
int ans = 0;
ans = max(ans,apair());
ans = max(ans,ttt());
ans = max(ans,bflush());
if(ans == 100){
cout << "Royal Flush" << endl;
continue;
} else if(ans == 50){
cout << "Straight Flush" << endl;
continue;
} else if(ans == 30){
cout << "Straight" << endl;
continue;
} else if(ans == 6){
cout << "Full House" << endl;
continue;
} else if(ans == 4){
cout << "Four of a Kind" << endl;
continue;
} else if(ans == 3){
cout << "Three of a Kind" << endl;
continue;
} else if(ans == 5){
cout << "Two Pairs" << endl;
continue;
} else if(ans == 2){
cout << "One Pair" << endl;
continue;
} else {
cout << "High Card" << endl;
continue;
}
}
return 0;
}
这里空空如也
有帮助,赞一个