重点在理解题意,最大的牌是顺子+同花。
扑克牌型
|
下面列出从大到小的扑克牌面. 这是所有的扑克通用规则。
1
| Royal Flush 同花大顺又称皇家同花顺 它是所有德州扑克中的王牌,即使您经常玩扑克,也很少见到这样的牌。好比打高尔夫球一杆进洞一样。它是由T(10)到Ace的清一色同花组成。 | |
| | |
2
| Straight Flush 同花顺 除了由最大同花所组成的同花大顺以外的同花组成的顺子。 | |
| | |
3
| Four-of-a-Kind 四条 四张同样的牌+任意一张牌 。 | |
| | |
4
|
Full House 俘虏或船牌或葫芦 | |
| | |
5
| Flush 五张同花 用五张同一花色但不相连的牌型组成,如都是五张同花,则谁的同花牌大谁赢。 | |
| | |
6
| Straight 五张顺子 由五张相连但不同花色的牌组成,在连牌中,Ace是既可作最大也可以作最小的牌。 | |
| | |
7
| Three-of-a-Kind 三条 即三张同样的牌。它有两种叫法,取决于一对牌是在您手中还是在桌上。一对在手中,桌上有一张,称之为“set”;v如手中有一张,桌上有一对,则称之为“Three of A Kind”。 | |
| | |
8
| Two Pair 两对 由五张牌中的两对牌组成。如果都有两对,则先比大对,再比小对 。 | |
| | |
9
| One Pair 一对 当不止一人有同样的一对牌时,则要比一对后面的牌,称之为“Kickers”。记住,德州扑克是挑选最好的五张牌去比。 | |
| | |
10
| High Card 大牌 无以上任何牌型时,决定牌的大小 。 |
//一下是看了某大神的80行代码后写的。。。
#include <iostream>
#include <cstring>
#include<cstdio>
#include<cstdlib>
#include <string>
#include<algorithm>
#define MARK -2147483647
using namespace std;
struct pai
{
char dian;
char col;
int num;
};
int win;
pai p[10];
pai bi1[5];
bool com(pai a,pai b){return a.num<=b.num;}
char name[10][20]={"highest-card","one-pair","two-pairs","three-of-a-kind","straight","flush","full-house","four-of-a-kind","straight-flush"};
void work()
{
int tonghua=1,shunzi=1;int zhangshu[5]={0};//用一个zhangshu数组判断一对、两对、三张、四张等
int i,Win=0;
for(i=1;i<5;++i){if(bi1[0].col!=bi1[i].col){tonghua=0;break; } }
for(i=1;i<5;++i){if(bi1[i].num!=bi1[i-1].num+1){shunzi=0;break; } }
if(bi1[0].num==1&&bi1[1].num==10&&bi1[2].num==11&&bi1[3].num==12&&bi1[4].num==13) shunzi=1;
for(i=0;i<5;++i)
{ int j;
for(j=0;j<5;++j)
{
if(bi1[i].num==bi1[j].num)++zhangshu[i];
}
}
sort(zhangshu,zhangshu+5);
if(zhangshu[4]==2&&zhangshu[2]==1) Win=1;
if(zhangshu[4]==2&&zhangshu[2]==2)Win=2;
if(zhangshu[4]==3&&zhangshu[0]==1)Win=3;
if(shunzi) Win=4;
if(tonghua)Win=5;
if(zhangshu[4]==3&&zhangshu[0]==2)Win=6;
if(zhangshu[4]==4)Win=7;
if(shunzi&&tonghua)Win=8;
if(Win>win)win=Win;
// cout<<win<<endl;
return;
}
int main()
{
//freopen("in.txt","r",stdin);
while(~scanf("%c%c",&p[0].dian,&p[0].col))
{ win=0;
if(p[0].dian=='T')p[0].num=10;
else if(p[0].dian=='J')p[0].num=11;
else if(p[0].dian=='Q')p[0].num=12;
else if(p[0].dian=='K')p[0].num=13;
else if(p[0].dian=='A')p[0].num=1;
else p[0].num=p[0].dian-'0';
getchar();
int i;
for(i=1;i<10;++i)
{
scanf("%c%c",&p[i].dian,&p[i].col);
getchar();
if(p[i].dian=='T')p[i].num=10;
else if(p[i].dian=='J')p[i].num=11;
else if(p[i].dian=='Q')p[i].num=12;
else if(p[i].dian=='K')p[i].num=13;
else if(p[i].dian=='A')p[i].num=1;
else p[i].num=p[i].dian-'0';
//cout<<p[i].dian<<p[i].col<<endl;
}
for(i=0;i<32;++i)//子集生成的二进制法
{
int in,i1=0,i2=0;
for(in=0;in<5;++in)
{
if(i&1<<in)
{
bi1[i1++]=p[in];
}
}
int ii;
for(ii=5;;++ii)
{
if(i1>=5)break;
bi1[i1++]=p[ii];
}
sort(bi1,bi1+5,com);
// for(int ik=0;ik<5;++ik)
// printf(" %c%c%d",bi1[ik].dian,bi1[ik].col,bi1[ik].num);
// cout<<endl;
work();
}
printf("Hand:");
for(i=0;i<5;++i)
printf(" %c%c",p[i].dian,p[i].col);
printf(" Deck:");
for(i=5;i<10;++i)
printf(" %c%c",p[i].dian,p[i].col);
printf(" Best hand:");
printf(" %s\n",name[win]);
}
return 0 ;
}