题意:给出五张牌,判断牌类型。
所有情况判断一下。
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int k;
}pai[6];
bool color[5];
int h[20];
bool cmp(struct node a,struct node b){
return a.k<b.k;
}
int main(){
int t,i;
char s[3];
cin>>t;
while(t--){
memset(color,false,sizeof(color));
for(i=0;i<5;i++){
scanf("%s",s);
if(s[1]=='S')color[1]=true;
else if(s[1]=='H')color[2]=true;
else if(s[1]=='D')color[3]=true;
else color[4]=true;
if(s[0]=='T')pai[i].k=10;
else if(s[0]=='J')pai[i].k=11;
else if(s[0]=='Q')pai[i].k=12;
else if(s[0]=='K')pai[i].k=13;
else if(s[0]=='A')pai[i].k=14;
else pai[i].k=s[0]-'0';
}
sort(pai,pai+5,cmp);
int cnt=0;
for(i=1;i<=4;i++){
if(color[i])cnt++;
}
if(cnt==1){//flush
if(pai[0].k==10){
printf("royal flush\n");
}else if(pai[4].k-pai[0].k==4||(pai[3].k==5&&pai[4].k==14)){
printf("straight flush\n");
}else printf("flush\n");
}else{
memset(h,0,sizeof(h));
int four=0,three=0,two=0;
for(i=0;i<5;i++){
h[pai[i].k]++;
}
for(i=2;i<15;i++){
if(h[i]==4)four=1;
else if(h[i]==3)three=1;
else if(h[i]==2)two++;
}
if(four){
printf("four of a kind\n");
}else if(three&&two){
printf("full house\n");
}else if(pai[4].k-pai[0].k==4||(pai[3].k==5&&pai[4].k==14)){
printf("straight\n");
}else if(three){
printf("three of a kind\n");
}else if(two==2){
printf("two pairs\n");
}else if(two){
printf("pair\n");
}else printf("high card\n");
}
}
return 0;
}