FOJ1504 Play Poker

题意:给出五张牌,判断牌类型。

所有情况判断一下。

#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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值