关于楼上题解的有些补充
为了方便阅读,我尽量写简洁点(绝对不是懒)
首先,想要保证能赢,一定要保证同花顺,不然有四张未知牌,对手能凑出同花顺。
所以第一步就判断同色,再判断顺。
然后因为是同色,每种数字只有一张
当然,特殊情况 A,2,3,4,5 除外,首先你要先有 A,不然人家可以用 A 凑一个同花顺;同时你要拥有 5 ,因为 5 相当于这个同花顺中最大的牌(你要知道这是最小同花顺,只要对面凑出同花顺就会输)。
以下为我的代码
#include <bits/stdc++.h>
using namespace std;
int f(string s) //将牌面统一转换为数字
{
if(s[0]=='T')
{
return 10;
}
if(s[0]=='J')
{
return 11;
}
if(s[0]=='Q')
{
return 12;
}
if(s[0]=='K')
{
return 13;
}
if(s[0]=='A')
{
return 14;
}
return s[0]-'0';
}
int main()
{
int t,h1,h2,c1,c2,c3;
cin>>t;
string te;
char io;
bool isok;
for(int b=0;b<t;b++)
{
isok=1;
cin>>te;
io=te[1];
h1=f(te);
cin>>te;
if(isok) //判断是否为同色,后面同上
{
isok=(io==te[1]);
}
h2=f(te);
cin>>te;
if(isok)
{
isok=(io==te[1]);
}
c1=f(te);
if(isok)
{
isok=(io==te[1]);
}
cin>>te;
if(isok)
{
isok=(io==te[1]);
}
c2=f(te);
cin>>te;
if(isok)
{
isok=(io==te[1]);
}
c3=f(te);
if(!isok)
{
cout<<"check"<<endl;
continue;
}
int a[5]={h1,h2,c1,c2,c3};
sort(a,a+5);
if(a[0]==2&&a[4]==14) //特殊处理A,2,3,4,5
{
a[4]=1;
sort(a,a+5);
}
for(int x=1;x<5;x++) //判断是否顺
{
if(a[x]-a[x-1]!=1)
{
isok=0;
break;
}
}
if(!isok)
{
cout<<"check"<<endl;
continue;
}
if(a[0]==1) //判断特殊情况A,2,3,4,5
{
if(max(h1,h2)==14&&min(h1,h2)==5)
{
cout<<"allin"<<endl;
continue;
}
else
{
cout<<"check"<<endl;
continue;
}
}
if(max(h1,h2)==a[4]||max(h1,h2)>9) //判断两张手牌是否有最大或有大于9
{
cout<<"allin"<<endl;
continue;
}
cout<<"check"<<endl;
}
}