#include<bits/stdc++.h>
using namespace std;
map<char,int> mp={{'T',10},{'J',11},{'Q',12},{'K',13},{'A',14}};
struct poker{
    int val;//牌值
    char sz;//花色
    bool operator <(const poker& a)const{//便于排序
        return val<a.val;
    }
}p[5];
bool flush(){
    for(int i=1;i<5;i++)
    if(p[i].sz!=p[i-1].sz)return false;
    return true;
}
bool straight(){
    for(int i=1;i<5;i++)
    if(p[i].val!=p[i-1].val+1)return false;
    return true;
}
bool four(){
    int cnt=1;
    for(int i=1;i<5;i++)
    if(p[i].val==p[i-1].val)cnt++;
    else cnt=1;
    return cnt==4;
}
bool three(){
    int cnt=1;
    for(int i=1;i<5;i++)
    if(p[i].val==p[i-1].val)cnt++;
    else cnt=1;
    return cnt==3;
}
bool full_house(){
    return (p[0].val==p[1].val&&p[1].val==p[2].val&&p[3].val==p[4].val)||(p[0].val==p[1].val&&p[2].val==p[3].val&&p[3].val==p[4].val);
}
bool two_pair(){
    int cnt=0;
    for(int i=1;i<5;i++)
    if(p[i].val==p[i-1].val)cnt++;
    if(cnt!=2)return false;
    return true;
}
bool one_pair(){
    int cnt=0;
    for(int i=1;i<5;i++)
    if(p[i].val==p[i-1].val)cnt++;
    if(cnt!=1)return false;
    return true;
}
int main(){
    for(int i=0;i<5;i++){
        string s;
        cin>>s;
        if(s[0]>='2'&&s[0]<='9')p[i].val=s[0]-'0';
        else p[i].val=mp[s[0]];
        p[i].sz=s[1];
    }
    sort(p,p+5);
    if(p[0].val==10&&p[1].val==11&&p[2].val==12&&p[3].val==13&&p[4].val==14&&flush())cout<<"Royal Flush";
    else if(straight()&&flush())cout<<"Straight Flush";
    else if(four())cout<<"Four of a Kind";
    else if(full_house())cout<<"Full House";
    else if(flush())cout<<"Flush";
    else if(straight())cout<<"Straight";
    else if(three())cout<<"Three of a Kind";
    else if(two_pair())cout<<"Two Pair";
    else if(one_pair())cout<<"Pair";
    else cout<<"High Card";
    return 0;
}
请使用c++编写以下程序并给出完整代码即可无需描述并详细理解题目和案例 题目描述在这个挑战中您必须确定一副五张牌中存在哪种扑克组合。每张卡片都是一个包含卡片值的字符串正面卡片的首字母大写和花色的小写首字母如下例所示:Ah ➞ A of 红桃Ks ➞ K of 黑桃3d ➞ 3 of 方块Qc ➞ Q of 梅花有10种不同的组合。以下列表按重要性降序排列:Royal Flush	A、K、Q、J、1

原文地址: http://www.cveoy.top/t/topic/bfv3 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录