#include #include #include #include using namespace std;

bool cmp(const pair<int,int>& a, const pair<int,int>& b){//排序函数 return a.second>b.second; }

string poker_hand(string a,string b,string c,string d,string e){ int A=0,K=0,Q=0,J=0,T=0;//初始化 map<char,int> m; m['A']=14;//赋初值 m['K']=13; m['Q']=12; m['J']=11; m['T']=10; m['9']=9; m['8']=8; m['7']=7; m['6']=6; m['5']=5; m['4']=4; m['3']=3; m['2']=2; map<char,int> M; M['h']=1; M['s']=2; M['d']=3; M['c']=4; vector<pair<int,int>> vec;//用于存储相同数字的个数以及数字本身 vec.push_back(make_pair(-1,-1)); vec.push_back(make_pair(-1,-1)); vec.push_back(make_pair(-1,-1)); vec.push_back(make_pair(-1,-1)); vec.push_back(make_pair(-1,-1)); for(int i=0;i<5;i++){ if(a[i]>='2'&&a[i]<='9'){ if(vec[a[i]-'0'-2].second==-1){//如果没找到相同数字 vec[a[i]-'0'-2].second=a[i]-'0';//存储数字 vec[a[i]-'0'-2].first=1;//个数加一 } else vec[a[i]-'0'-2].first++;//如果找到了,个数加一 } else{ if(vec[m[a[i]]-2].second==-1){ vec[m[a[i]]-2].second=m[a[i]]; vec[m[a[i]]-2].first=1; } else vec[m[a[i]]-2].first++; } if(a[i]=='A') A++;//记录A,K,Q,J的张数 if(a[i]=='K') K++; if(a[i]=='Q') Q++; if(a[i]=='J') J++; if(a[i]=='T') T++; if(i==0){ if(a[i+1]==b[i+1]&&a[i+1]==c[i+1]&&a[i+1]==d[i+1]&&a[i+1]==e[i+1]){ //判断Royal Flush if(vec[0].second==-1) return "Royal Flush";//如果没有相同数字,返回Royal Flush else return "Straight Flush";//否则返回Straight Flush } else if(vec[0].first==1&&vec[1].first==1&&vec[2].first==1&&vec[3].first==1&&vec[4].first==1){ //判断Straight if(a[i+1]==b[i+1]&&a[i+1]==c[i+1]&&a[i+1]==d[i+1]&&a[i+1]==e[i+1]) return "Straight Flush"; else return "Straight"; } else{ sort(vec.begin(),vec.end(),cmp);//按个数从多到少排序 if(vec[0].first==4) return "Four of a Kind";//判断Four of a Kind else if(vec[0].first==3&&vec[1].first==2) return "Full House";//判断Full House else if(a[i+1]==b[i+1]&&a[i+1]==c[i+1]&&a[i+1]==d[i+1]&&a[i+1]==e[i+1]) return "Flush";//判断Flush else if(vec[0].first==3) return "Three of a Kind";//判断Three of a Kind else if(vec[0].first==2&&vec[1].first==2) return "Two Pair";//判断Two Pair else if(vec[0].first==2) return "Pair";//判断Pair else return "High Card";//否则返回High Card } } } }

int main(){ string a,b,c,d,e; cin>>a>>b>>c>>d>>e; cout<<poker_hand(a,b,c,d,e)<<endl;//输出 return 0; }

请使用c++编写以下程序并给出完整代码 题目描述在这个挑战中您必须确定一副五张牌中存在哪种扑克组合。每张卡片都是一个包含卡片值的字符串正面卡片的首字母大写和花色的小写首字母如下例所示:Ah ➞ A of 红桃Ks ➞ K of 黑桃3d ➞ 3 of 方块Qc ➞ Q of 梅花有10种不同的组合。以下列表按重要性降序排列:Name	描述Royal Flush	A、K、Q、J、10都同一套花色。S

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

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