Poker is a family of gambling card games involving betting and individual play, whereby the winner is determined by the ranks and combinations of players' cards, some of which remain hidden until the end of the game.
Each card has a suit (Club, Diamond, Heart, Spade) and a rank. The ranks are, from lowest (least valuable) to highest (most valuable): ace (low), 2, 3, 4, 5, 6, 7, 8, 9, 10, jack, queen, king, ace (high). Although only one ace card exists within each suit, and it is usually ranked as the highest card, under some circumstances the ace card will be treated as the lowest. The suit itself has no bearing on the worth of the card and is only used to determine which category a particular hand belongs to.
Poker hands are made of combinations of 2 to 5 cards in the hand. Cards that are not used in the combination are called kicker cards and can be used to break ties if needed.
The ranking of poker hands (best to worst) is as follows:
A Royal Flush is a hand that includes a 10, Jack, Queen, King, and Ace all of the same suit. If both hands have a Royal Flush, the hands tie.
A Straight Flush is a hand where the ranks of the cards are sequential and they all share the same suit. For example, a hand that has the 5, 6, 7, 8, and 9 of Clubs is a Straight Flush. An Ace can be either low (come before a 2) or high (come after a King). When comparing Straight Flushes, the straight with the highest ranked card wins. If the hands have the same highest ranked card, the hands tie.
A Four of a Kind is a hand that contains four cards of the same rank. For example, a hand that has the 2 of Clubs, 2 of Hearts, 2 of Diamonds, 2 of Spades, and any other card is a Four of a Kind. When comparing Four of a Kinds, the hand with the set of four cards with the highest rank wins.
A Full House is a hand that contains three cards of one rank and two cards of another rank. For example, a hand that has the 2 of Clubs, 2 of Hearts, 2 of Diamonds, 3 of Clubs, and 3 of Hearts is a Full House of 2s over 3s. When comparing Full Houses, the hand with the set of three cards with the highest rank wins.
A Flush is a hand of five cards that all share the same suit. For example, a hand that has the Ace of Spades, 3 of Spades, 7 of Spades, 10 of Spades, and King of Spades is a Flush. When comparing Flushes, the hand with the highest ranked card wins. If both hands have the same high card, compare the next highest card and repeat until a winner is found. If both hands have the same five ranks, the hands tie.
A Straight is a hand where the ranks of the cards are sequential. For example, a hand that has the 5 of Clubs, 6 of Hearts, 7 of Spades, 8 of Diamonds, and 9 of Clubs is a Straight. Like a Straight Flush, an Ace can be either high or low. When comparing Straights, the straight with the highest ranked card wins. If the hands have the same highest ranked card, the hands tie.
A Three of a Kind is a hand that has three cards of the same rank. For example, a hand that has the 2 of Clubs, 2 of Hearts, 2 of Diamonds, 3 of Clubs, and 4 of Clubs is a Three of a Kind of 2s. When comparing Three of a Kinds, the hand with the highest ranking set wins.
A Two Pair is a hand that has two sets of two cards of the same rank. For example, a hand that has the 2 of Clubs, 2 of Hearts, 3 of Clubs, 3 of Hearts, and the 4 of Clubs is a Two Pair. When comparing Two Pairs, the hand that has the highest ranking set wins. If both hands have the same highest ranking set, the hand with the second highest ranking set wins. If those sets have the same rank, the hand with the highest ranking kicker card wins. If the kicker cards have the same rank, the hands tie.
A One Pair is a hand that has one set of two cards of the same rank. For example, a hand that has the 2 of Clubs, 2 of Hearts, 3 of Clubs, 4 of Clubs, and 5 of Clubs is a One Pair. When comparing One Pairs, the hand with the highest rank set wins. If both hands have the same highest ranking set, then the hand with the highest kicker card is the winner. If both hands have the same high kicker card, compare the next highest kicker card and repeat until a winner is found. If both hands have the same kicker cards, the hands tie.
If neither hand has a special combination, the hand with the card with the highest rank wins. If both hands have the same high card, compare the next highest card and repeat until a winner is found. If both hands have the same five cards, ignoring suits, the hands tie.
Input
Input consists of a number of rounds to score, then two hands for each round.
The first line contains an integer W (1 <= W <= 200) indicating the number of rounds to score.
After the first line, there will be W pairs of lines of strings that describe a poker hand. The strings will be 5 rank and suit combinations separated by spaces. Single digit ranks (2 through 9) are represented by that number; Ten, Jack, Queen, King, and Ace are each represented by the (capitalized) first letter of the word. The suit is also represented by the (capitalized) first letter of its name. For example, "2C 4D 8H TD KS" is the hand that has the 2 of Clubs, 4 of Diamonds, 8 of Hearts, 10 of Diamonds, and King of Spades. Within each round, there will be no duplicate cards.
Output
For each pair of hands, output a single line containing the hand that wins the poker round or the string Tie if the hands tie. The hand should be displayed the same as it was given in the input file.
Sample Input
5 TC JC QC KC AC 9D TD JD QD KD 2C 2D 2S 3S 3D TC JD QH KS AS 2D 4S 6H TS AS 8S 8D 3H KS AH 2S JS QS KS AH 3S JH QD KH AS 2S 2H AS AH KD 2D 3C AD AC KC
Sample Output
TC JC QC KC AC 2C 2D 2S 3S 3D 8S 8D 3H KS AH 3S JH QD KH AS Tie
同花顺玩过吗!!!玩过的根本不看翻译就是同花顺比大小啦~不知道的小朋友一定是和我一样不赌博的好学生
手上会有五张牌,双方手中牌级别高的获胜,级别从大到小分别为:
同花顺:手上五张牌都是同种花色,且构成顺子。
四张:手上有四张一样的牌。(不要问为什么没有五张都一样,好好想想)
三带二:五张牌里边有三张一样的,剩下两张也一样。
同花:五张牌都是同一个花色。
顺子:五张牌都是顺序的。(特殊情况:2,3,4,5,A相当于1,2,3,4,5)
三张:五张牌里边有三张一样的,剩下两张与三张都不一样且各自不一样。
两对两张:五张牌里边有两对各自一样的,剩下的一张与这两对都各自不一样。
两张:五张牌里边有一对一样的,剩下的三张与这一对都不一样且各自不一样。
单张:五张牌都各自不一样。
需要注意如果双方手上都有四张相等的牌,那么点数大的获胜。其他情况也同理。如果数量相同的牌点数相同一样,则把牌从散牌里边从大到小比较直到出现一方牌点数比另一方大,获得胜利。
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct pork
{
int rank_int;
char rank_char;
char color;
};
bool cmp(int a,int b)
{
return a<b;
}
void init(pork *h)
{
for(int i=0; i<5; i++)
{
cin>>h[i].rank_char>>h[i].color;
switch(h[i].rank_char)
{
case 'T': h[i].rank_int=10; break;
case 'J': h[i].rank_int=11; break;
case 'Q': h[i].rank_int=12; break;
case 'K': h[i].rank_int=13; break;
case 'A': h[i].rank_int=14; break;
default: h[i].rank_int=h[i].rank_char-'0';
}
}
}
void print(pork *h)
{
for(int i=0; i<5; i++)
{
if(i==0)
printf("%c%c",h[i].rank_char,h[i].color);
else
printf(" %c%c",h[i].rank_char,h[i].color);
}
printf("\n");
}
int findx(int *h,int target_count)
{
int prev=0;
int sum=0;
int s=0;
for(int i=0; i<5; i++)
{
if(h[i]==prev)
sum++;
else
{
if(sum==target_count)
s++;
prev=h[i];
sum=1;
}
}
if(sum==target_count)
s++;
if(s==1)
return 1;
if(s==2)
return 2;
else
return 0;
}
void compare(pork *h1,pork *h2)
{
int x1,x2;
int four1=0,four2=0,three1=0,three2=0,two1=0,two2=0;
int colorflag1=1,colorflag2=1; //同花
int flushflag1=1,flushflag2=1; //顺子
int rankh1[5],rankh2[5];
for(int i=0; i<5; i++)
{
rankh1[i]=h1[i].rank_int;
rankh2[i]=h2[i].rank_int;
}
sort(rankh1,rankh1+5,cmp);
sort(rankh2,rankh2+5,cmp);
if(rankh1[0]==2&&rankh1[1]==3&&rankh1[2]==4&&rankh1[3]==5&&rankh1[4]==14)
rankh1[4]=1;
sort(rankh1,rankh1+5,cmp);
if(rankh2[0]==2&&rankh2[1]==3&&rankh2[2]==4&&rankh2[3]==5&&rankh2[4]==14)
rankh2[4]=1;
sort(rankh2,rankh2+5,cmp);
for(int i=1; i<5; i++)
{
if(h1[i].color!=h1[0].color)
colorflag1=0;
if(h2[i].color!=h2[0].color)
colorflag2=0;
}
for(int i=1; i<5; ++i)
{
if(rankh1[i]!=rankh1[i-1]+1)
flushflag1=0;
if(rankh2[i]!=rankh2[i-1]+1)
flushflag2=0;
}
four1=findx(rankh1,4);
four2=findx(rankh2,4);
three1=findx(rankh1,3);
three2=findx(rankh2,3);
two1=findx(rankh1,2);
two2=findx(rankh2,2);
while(1)
{
if(colorflag1&&flushflag1)
{
x1=9;
break;
}
else if(four1)
{
x1=8;
break;
}
else if(three1&&two1==1)
{
x1=7;
break;
}
else if(colorflag1&&flushflag1==0)
{
x1=6;
break;
}
else if(flushflag1&&colorflag1==0)
{
x1=5;
break;
}
else if(three1)
{
x1=4;
break;
}
else if(two1==2)
{
x1=3;
break;
}
else if(two1==1)
{
x1=2;
break;
}
else
{
x1=1;
break;
}
}
while(1)
{
if(colorflag2&&flushflag2)
{
x2=9;
break;
}
else if(four2)
{
x2=8;
break;
}
else if(three2&&two2==1)
{
x2=7;
break;
}
else if(colorflag2&&flushflag2==0)
{
x2=6;
break;
}
else if(flushflag2&&colorflag2==0)
{
x2=5;
break;
}
else if(three2)
{
x2=4;
break;
}
else if(two2==2)
{
x2=3;
break;
}
else if(two2==1)
{
x2=2;
break;
}
else
{
x2=1;
break;
}
}
if(x1-x2!=0)
{
if(x1-x2>0)
print(h1);
else if(x1-x2<0)
print(h2);
}
else
{
int flag=1;
for(int i=4; i>=0; i--)
{
if(rankh1[i]!=rankh2[i])
{
flag=0;
if(rankh1[i]-rankh2[i]>0)
{
print(h1);
break;
}
else if(rankh1[i]-rankh2[i]<0)
{
print(h2);
break;
}
}
}
if(flag==1)
{
cout<<"Tie"<<endl;
}
}
}
int main()
{
int n;
cin>>n;
while(n--)
{
pork h1[5],h2[5];
init(h1);
init(h2);
compare(h1,h2);
}
return 0;
}