## 10315 - Poker Hands

All about problems in Volume 103. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

liangchene
New poster
Posts: 12
Joined: Thu May 19, 2005 6:07 am
Thanks a lot.

it got accepted.

there's this bug in my program.

when you do the big shift, you have to have brackets around it

for example:

1+(2<<2) is different from 1+2<<2.

Strange.

anywayz, thx

Marcin Panasiuk
New poster
Posts: 1
Joined: Fri Feb 24, 2006 5:51 pm

### 10315 Interpretation problemas with straight

Pablo:

Your program works quite good but only for cards from one deck. Unfortunatelly, there are tests when one hands has two cards, which are exactly the same. Problem appears for example when you have a flush, and simultanously a pair or two pairs... and so on. The value returning by function gamePoints() is much more higher than for example full house, four of a house or even flush straight.

Try this input:
3H 5H AH AH 3H 2H 2C AC AD 2D
Your output is "Black wins.", but there should be "White wins."

PS. Btw, this problem is tricky, or rather tests are tricky, since by "cards dealt from the deck" one can think there are no duplicates.
"A designer knows he had achieved perfection not when there is nothing left to add, but when there is nothing left to take away."

devious
New poster
Posts: 13
Joined: Wed Feb 22, 2006 1:26 am

### 10315: Poker Hands (clarification questions)

So....

Four of a Kind:

It says to rank by value of four cards if both have a four of a kind. Can there be more than one deck? Because it doesn't say there can't, and if so, would I rank the hand with the 5th card being the kicker(deciding card)?

Full House:

More or less the same as above, but if They are same three cards, do I rank by the other 2 cards? so is a QQQKK higher than a QQQJJ? Or are they the same?

Flush:

It says to use rule sof highest card. That would mean a 3579A flush is higher than a 2579A flush, right?

Straight:

It says it ranks it by its highest card, is an Ace ever considered a 1 in this program? If so, an A2345 Straight loses to a 23456 straight. But if it is not considered a 1, then it would win

Thanks ^_^

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada
IIRC, there is only one deck.

For the flush - yes. Sort hands in descending order and compare cards one by one.

For the straight - A2345 is not a straight in this problem (as described, 2 is lowest, A is highest)

Darko

nev4
New poster
Posts: 15
Joined: Sun Apr 30, 2006 10:19 am
Location: Lithuania
Thx, Jan for sample input. It revealed that i have used > instead of < in one place of code.

Germano
New poster
Posts: 2
Joined: Sat Oct 16, 2004 9:15 am

### more tests case

i did some more test cases to test my problem:
2S 3S 4S 5S 6S 7H 8H 9H TH JH
5C 5C 2H 4H 6H 5C 5C 2H 4H 6H
AS KS JH TC 9S AH KS JS 9H 8C
5C 5C 2H 4H 6H 4H 4H 2C 5H 6H
7C 7C 2H 5H 6H 7H 7H 2C 4H 6H
7C 7C 3H 5H 6H 7H 7H 2C 5H 6H
7C 7C 3H 5H 6H 7H 7H 3C 5H 6H
2C 2C 4H 4H 5S 4H 4H 3S 3S 5S
2C 2C 4H 4H 6S 4H 4H 2S 2S 5S
2C 2C 4H 4H 5S 4H 4H 2S 2S 5S
7C 7C 7D 2H 5S 2D 6D 7S 7S 7D
8C 8C 8D 2H 5S 2D 6D 7S 7S 7D
7C 3D 4H 5S 6C 2C 3D 4H 5S 6C
3C 4C 6C 8C TC 2C 4C 6C 8C TC
3C 4C 6C 8C TC 3C 4C 6C 8C TC
3C 3D 4H 4S 4C 3C 3D 4H 4S 4C
3C 3D 5H 5S 5C 3C 3D 4H 4S 4C
2C 2D 5H 5S 5C 3C 3D 4H 4S 4C
9C 9D 9H 9S 2C 9C 9D 9H 9S 2C
TC TD TH TS 2C 9C 9D 9H 9S 2C
3S 4S 5S 6S 7S 2S 3S 4S 5S 6S
2S 3S 4S 5S 6S 2S 3S 4S 5S 6S

my acc code returns:
Black wins.
Black wins.
White wins.
Tie.
Black wins.
Black wins.
Black wins.
Black wins.
Tie.
Tie.
Black wins.
Tie.
Tie.
Black wins.
Black wins.
Black wins.
Tie.
Tie.
Black wins.
Black wins.
Tie.
Black wins.
Black wins.
Tie.

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:
It's really tricky... I can't solve this problem though all of Jan's test case
passed...

If anyone have critical test case for this problem, plz tell me about it.
And I have another question.
Full House: 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards.
Four of a kind: 4 cards with the same value. Ranked by the value of the 4 cards.
That was problem statements. According to this script, Full House or Four
of a Kind would not count remaining card for rank. Is it right or wrong??
I love Problem Solving!!!   Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
soyoja wrote:
Full House: 3 cards of the same value, with the remaining 2 cards forming a pair. Ranked by the value of the 3 cards.
Four of a kind: 4 cards with the same value. Ranked by the value of the 4 cards.
That was problem statements. According to this script, Full House or Four
of a Kind would not count remaining card for rank. Is it right or wrong??
Its obviously right. All of the cards are from a single set, so a card can't occur twice. Now suppose you have a Full-House. 5H 5D 5S 3D 3H. If there is another full house with three '5' and a pair, then you would check the pair. But there is only one '5' left, so you cant get it. And same reason for 'Four of a Kind'.

However, here are some cases. If your code passes then you can post your code.

Input:

Code: Select all

``````3H 4S 8S KD AS QC QH 4H 6D 5S
9S 3C 7D 2S JH AD 4D JS 6H 6D
KH 6C 7S TH 5S 3S 7C 5H AC 9D
6H KD 3D 6D QS 4C 5C 9D 6S KH
9D JS AS 9S 6H 5H KD QD JC JH
QD 7D 3D 6D 4C 2S 5C JC 2D TS
9H 9D 2S QD 3S 5D QH 3C AH 9C
9D 3S AD QD 8S 4H KC 8H TC 2D
9S 2S 8C TH KS AD 2H 3D JS 6H
JC AH QD TS 8H 9C TH JS 8C AD
JC KH KS 4D 2S 5C QD 8C JD AS
KS QC 7H JC 3C TD 5C 5S 8C 9C
3S 2H 3C 6S QS 9C 7H 4S 8C QH
9S QC TD 2D 6C KH 2H JH 3S KC
JS 8D KD AS 5D 6C JD 7D 7H 3S
QD AC 5C 3D JD 3C 6H JC TD 7S
7D JH 4D KC 5C 3D 9S 7C 3H 6H
9H TH 9C TD KD 7C 9S AH 8S 5C
8S JD QS 5D QH TS KH 8C 4S 9D
QD JD AH KD 5H 5D 8S TD QS KC
TD JS AC KS 3S 7D KD 2H 2D QS
TD 5S 7H KC 4C TC 9S QC JC QD
JD KD QH 4C 9S TS 7S 8H JC QD
KH AH QH 2H 3H AD 2D 3D 4D 5D``````
Output:

Code: Select all

``````White wins.
White wins.
White wins.
Black wins.
White wins.
White wins.
Black wins.
Black wins.
White wins.
Black wins.
Black wins.
White wins.
Black wins.
White wins.
White wins.
Black wins.
White wins.
Black wins.
Black wins.
Black wins.
White wins.
White wins.
Black wins.
Black wins.``````
Hope these help.
Ami ekhono shopno dekhi...
HomePage

soyoja
Experienced poster
Posts: 106
Joined: Sun Feb 17, 2002 2:00 am
Location: Seoul, South Korea
Contact:
My solution still received WA..
Thx, Jan. My program passed all of your test case, but it cannot pass the
OJ's test. I found one critical input, so I modified my code. But I recieved
WA..

My critical Input
4C 4C 8C 7C 5C 3D 3D 8D 7D 6D
In this test case, both hands are flush. According to the problem statement,
hands which are both flushes are ranked using the rules for High Card.(Do not consider remaining pairs of cards! )
So my answer is
White wins.

My solution received WA repetedly.... Here is my code...
Sorry. It's so dirty and complicated..

Code: Select all

``````
#include <iostream>
#include <algorithm>
#include <string>
#include <memory>

using namespace std;

struct data
{
int same;		// count same card numbers
int pair;		// count the numbers of pair
bool straight;	// count it is straight or not
bool equal;		// count it is flush or not
};

data Rank;

int comp(string dat1, string dat2 )
{
if( dat1 > dat2 ) return 1;
else return 0;
}

int check(string *card, int *numbers, int *pa)
{
int a, cnt = 0, same = 0, grade = 0;
bool isStraight;
data score;
score.equal = score.straight = false, score.pair = score.same = 0; // initializing

isStraight = true;
sort( &card, &card, comp );

for( a = 0; a < 5; a++ )
{
if( card[a] >= 'A' && card[a] <= 'Z' ) numbers[a] = card[a] - 'A' + 10;
else numbers[a] = card[a] - '0';

if( a >= 1 )
{
if( pa != 0 )	// pa saved pairs number.
{
if( numbers[a] != pa )
{
if( numbers[a] == numbers[a-1] ) same++, pa = numbers[a];
}
else
{
same++;
}
}
else
{
if( numbers[a] == numbers[a-1] ) same++, pa = numbers[a];
}

if( numbers[a-1] - numbers[a] != 1 ) isStraight = false;
}
}
if( isStraight ) score.straight = true;

for( a = 0; a < 5; a++ )	// for check flush
{
if( card == card[a] ) cnt++;
}

score.same = same;
if( pa ) score.pair = 2;
else if( pa ) score.pair = 1;
if( cnt == 5 ) score.equal = true;

if( score.straight ) grade = 4;
if( score.equal ) grade = 5;
for( a = 1; a < 9; a++ ) 	// decide the rank;
{
if( score.straight == Rank[a].straight && score.equal == Rank[a].equal &&
score.same == Rank[a].same && score.pair == Rank[a].pair && (grade < a ) )
grade = a;
}

return grade;
}

int main()
{
int a, grade1, grade2, numbers1, numbers2, pa1, pa2;
string white, black;

Rank.straight = false, Rank.equal = false, Rank.same = 1, Rank.pair = 1;  // one pair
Rank.straight = false, Rank.equal = false, Rank.same = 2, Rank.pair = 2;  // two pair
Rank.straight = false, Rank.equal = false, Rank.same = 2, Rank.pair = 1;  // Three of a kind
Rank.straight = true,  Rank.equal = false, Rank.same = 0, Rank.pair = 0;  // straight
Rank.straight = false, Rank.equal = true,  Rank.same = 0, Rank.pair = 0;  // flush
Rank.straight = false, Rank.equal = false, Rank.same = 3, Rank.pair = 2;  // full house
Rank.straight = false, Rank.equal = false, Rank.same = 3, Rank.pair = 1;  // Four of a kind
Rank.straight = true,  Rank.equal = true,  Rank.same = 0, Rank.pair = 0;  // straight flush

while( cin )
{
for( a = 0; a <= 4; a++ )
{
cin >> black[a];
if( black[a] == 'T' ) black[a] = 'A';		// for easy using, convert char.
else if( black[a] == 'J' ) black[a] = 'B';
else if( black[a] == 'Q' ) black[a] = 'C';
else if( black[a] == 'K' ) black[a] = 'D';
else if( black[a] == 'A' ) black[a] = 'E';
}

for( a = 0; a <= 4; a++ )
{
cin >> white[a];
if( white[a] == 'T' ) white[a] = 'A';
else if( white[a] == 'J' ) white[a] = 'B';
else if( white[a] == 'Q' ) white[a] = 'C';
else if( white[a] == 'K' ) white[a] = 'D';
else if( white[a] == 'A' ) white[a] = 'E';
}

memset( pa1, 0, sizeof(pa1) );
memset( pa2, 0, sizeof(pa2) );
memset( numbers1, 0, sizeof(numbers1) );
memset( numbers2, 0, sizeof(numbers2) );

grade1 = check( black, numbers1, pa1 );
grade2 = check( white, numbers2, pa2 );

sort( &pa1, &pa1 );
sort( &pa2, &pa2 );

if( grade1 == 5 && grade2 == 5 )
{
memset( pa1, 0, sizeof(pa1) );
memset( pa2, 0, sizeof(pa2) );
}

if( grade1 > grade2 ) cout << "Black wins." << endl;
else if( grade1 < grade2 ) cout << "White wins." << endl;
else
{
if( pa1 > pa2 ) cout << "Black wins." << endl;
else if( pa1 < pa2 ) cout << "White wins." << endl;
else
{
if( pa1 > pa2 ) cout << "Black wins." << endl;
else if( pa1 < pa2 ) cout << "White wins." << endl;
else
{
for( a = 0; a < 5; a++ )
{
if( numbers1[a] > numbers2[a] )
{
cout << "Black wins." << endl;
break;
}
else if( numbers1[a] < numbers2[a] )
{
cout << "White wins." << endl;
break;
}
else if( a == 4 ) cout << "Tie." << endl;
}
}
}
}
}

return 0;
}
``````
I love Problem Solving!!!   Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:
I ran your code from an input file and it returned one extra answer at the end.
May be the following line is the reason...

Code: Select all

``while( cin )``
Hope it helps.
Ami ekhono shopno dekhi...
HomePage

skysbsb
New poster
Posts: 1
Joined: Fri May 11, 2007 12:46 am
i am trying solvind this problem with C++.. i try hard and not take any accepted submissions...

so, i get this source, in C.. submited and its ok!

Code: Select all

``````#include <stdio.h>
#define get_value(x) ((x) / 10)
#define get_suit(x) ((x) % 10)

int encode_card(char *card)
{
int result;
switch (card) {
case 'T': result = 100; break;
case 'J': result = 110; break;
case 'Q': result = 120; break;
case 'K': result = 130; break;
case 'A': result = 140; break;
default : result = (card - '0') * 10;
}
switch (card) {
case 'H': result += 1; break;
case 'D': result += 2; break;
case 'S': result += 3; break;
case 'C': result += 4; break;
}
return result;
}

long get_hand_value(int hand)
{
int i, j, max, temp;
int value, suit;
long result;

for (i = 0; i < 4; i++) {
max = i;
for (j = i + 1; j < 5; j++)
if (hand[j] > hand[max])
max = j;
temp = hand[i];
hand[i] = hand[max];
hand[max] = temp;
}
for (i = 0; i < 5; i++)
{
value[i] = get_value(hand[i]);
suit[i] = get_suit(hand[i]);
}
/* straight flush */
if (value + 1 == value && suit == suit
&& value + 2 == value && suit == suit
&& value + 3 == value && suit == suit
&& value + 4 == value && suit == suit)
result = (9 << 20) + (value << 16);
/* four of a kind.*/
else if (value == value || value == value)
result = (8 << 20) + (value << 16);
/* full house. */
else if (value == value && value == value)
result = (7 << 20) + (value << 16);
else if (value == value && value == value)
result = (7 << 20) + (value << 16);
/* flush */
else if (suit == suit && suit == suit
&& suit == suit && suit == suit)
result = (6 << 20) + (value << 16) + (value << 12) + (value << 8) + (value << 4) + value;
/* straight */
else if (value + 1 == value && value + 2 == value
&& value + 3 == value && value + 4 == value)
result = (5 << 20) + (value << 16);
/* three of a kind */
else if (value == value || value == value
|| value == value)
result = (4 << 20) + (value << 16);
/* two pairs*/
else if (value == value && value == value)
result = (3 << 20) + (value << 16) + (value << 12) + (value << 8);
else if (value == value && value == value)
result = (3 << 20) + (value << 16) + (value << 12) + (value << 8);
else if (value == value && value == value)
result = (3 << 20) + (value << 16) + (value << 12) + (value << 8);
/* pair */
else if (value == value)
result = (2 << 20) + (value << 16) + (value << 12) + (value << 8);
else if (value == value)
result = (2 << 20) + (value << 16) + (value << 12) + (value << 8);
else if (value == value)
result = (2 << 20) + (value << 16) + (value << 12) + (value << 8);
else if (value == value)
result = (2 << 20) + (value << 16) + (value << 12) + (value << 8);

/* high card */
else
result = (1 << 20) + (value  << 16) + (value << 12) + (value << 8) + (value << 4) + value;

return result;
}

int main(void)
{
char line;
int hand;
long hand_value;
int i, j, t;
while (gets(line) && *line) {
t = 0;
for (i = 0; i < 2; i++) {
for (j = 0; j < 5; j++) {
while (line[t] == ' ')
t++;
hand[i][j] = encode_card(line + t);
t += 2;
}
hand_value[i] = get_hand_value(hand[i]);
}
if (hand_value > hand_value)
puts("Black wins.");
else if (hand_value < hand_value)
puts("White wins.");
else
puts("Tie.");
}
}

/* @END_OF_SOURCE_*/

``````
i make a program to gen some combinations of hands..
2S 5S 5S KS TD 3C 5D KH KH QD

who win this input?
black = 2S 5S 5S KS TD pair of 5
white = 3C 5D KH KH QD pair of K

? white have the biger pair (K), but this C source says black wins.. why UVA judge accepted this source? in case of pair, the biger pair have to win?

i just don't understood..

Codemonkey2000
New poster
Posts: 9
Joined: Sun Dec 09, 2007 6:46 am
Hi, I'm wondering, is there a more efficient way of determining a hand. I was thinking about looking at the probability of getting a hand, and seeing if it matches the probability of getting say a flush.

CMG
New poster
Posts: 37
Joined: Sat Dec 08, 2007 5:01 am
Location: ...
Not sure exactly Codemonkey2000.

However I keep getting WA and I have no clue why. I have done all of Jan's inputs and all match. Here is what I have for Java.

Code: Select all

``````public class Main {
private static int[] xlat = {0,0,0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,12,0,0,1,0,0,0,2,0,9,11,0,0,0,0,0,10,0,3,8};

public static void main(String args[]) {
int i,p,c,high,sp,sc,black,white,j;
int[][] suits;
int[][] cards;
int[][] kind;
while(true) {
suits = new int;
cards = new int;
kind = new int;
black = 0;
white = 0;
try {
i = 0;
p = 0;
while(i<10) {
if(i==5) p++;
c = System.in.read();
while(c>0 && (c<0x32 || c>0x54)) {
c = System.in.read();
}
cards[p][xlat[c-0x30]]++;//determine amount of each number
suits[p][xlat[System.in.read()-0x30]]++;//determine amount of each suit
i++;
}
} catch(Exception e) {
return;
}
high = 0;
sp = 0;
sc = 0;
for(i=12;i>=0;i--) {
p = cards[i];
c = cards[i];
j = high<0?-high:high; //determine which hand is better
if(p>c) {
if(p>j) {
high = p;
}
} else if(c>p) {
if(c>j) {
high = -c;
}
}
if(p==1) {//check if black has striaght
sp++;
if(sp==5) {
black += 13;
}
} else {
if(sp>0) {
sp--;
}
}
if(c==1) {//check if white has striaght
sc++;
if(sc==5) {
white += 13;
}
} else {
if(sc>0) {
sc--;
}
}
if(p>kind) {//determine if black has any multiples
kind = kind;
kind = p;
} else if(p>kind) {
kind = p;
}
if(c>kind) {//determine if white has any multiples
kind = kind;
kind = c;
} else if(c>kind) {
kind = c;
}
}
for(i=0;i<4;i++) {
p = suits[i];
c = suits[i];
if(p==5) {
black += 14;
}
if(c==5) {
white += 14;
}
}
black += (2*kind+kind-3)*3;//high card=0, pair = 6, two pair = 9, three of a kind = 12, full house = 15, four of a kind = 18;
white += (2*kind+kind-3)*3;
if(white>black) {
System.out.println("White wins.");
} else if(black>white) {
System.out.println("Black wins.");
} else {
if(high>0) {
System.out.println("Black wins.");
} else if(high<0) {
System.out.println("White wins.");
} else {
System.out.println("Tie.");
}
}
}
}
}``````

taz_debian
New poster
Posts: 1
Joined: Sat May 31, 2008 6:02 am

### Re: 10315 - Poker Hands

my question is :
A2345 is straight??

diego_engcomp
New poster
Posts: 9
Joined: Sat Jul 18, 2009 1:18 am

### Re: 10315 - Poker Hands

Hi, I don't now why I am getting WA on this problem. My code passed in all test cases on this forum and I have a friend that get AC on this problem and I made 30 test cases and my code and the code of him had the same result. Both codes do practically the same thing but in different ways. Its a big code buts is easy to understand. Can anybody tell me what I do wrong? Thanks and sorry for my english.

Code: Select all

``````#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

void high_card(vector<int> v_black, vector<int> v_white){
int ncards=0, i=12, j=12;
while(true){
for( ; ;i--){
if(v_black[i]>0){
v_black[i]--;
break;
}
}
for( ; ;j--){
if(v_white[j]>0){
v_white[j]--;
break;
}
}
ncards++;
if(i!=j){
if(i>j)
cout<<"Black wins."<<endl;
else
cout<<"White wins."<<endl;
break;
}
if(ncards==5){
cout<<"Tie."<<endl;
break;
}
}
}

bool one_pair(vector<int> &v_black, vector<int> &v_white){
int b_points=0, w_points=0;
vector<int>::iterator ite;
if ((ite=find(v_black.begin(),v_black.end(),2))!=v_black.end())
b_points=ite-v_black.begin()+2;
if ((ite=find(v_white.begin(),v_white.end(),2))!=v_white.end())
w_points=ite-v_white.begin()+2;
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
high_card(v_black,v_white);
return true;
}
return false;
}

bool two_pairs(vector<int> v_black, vector<int> v_white){
int b_hpair=0, b_lpair=0, b_rcard=0, w_hpair=0, w_lpair=0, w_rcard=0;
for(int i=0; i<13; i++){
if(v_black[i]==2){
b_lpair=b_hpair;
b_hpair=i+2;
}
if(v_black[i]==1)
b_rcard=i+2;
}
for(int i=0; i<13; i++){
if(v_white[i]==2){
w_lpair=w_hpair;
w_hpair=i+2;
}
if(v_white[i]==1)
w_rcard=i+2;
}
if((b_hpair!=0 && b_lpair!=0) || (w_hpair!=0 && w_lpair!=0)){
if(b_hpair>w_hpair)
cout<<"Black wins."<<endl;
else if (w_hpair>b_hpair)
cout<<"White wins."<<endl;
else{
if(b_lpair>w_lpair)
cout<<"Black wins."<<endl;
else if (w_lpair>b_lpair)
cout<<"White wins."<<endl;
else{
if(b_rcard>w_rcard)
cout<<"Black wins."<<endl;
else if (w_rcard>b_rcard)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
}
}
return true;
}
return false;
}

bool three_of_a_kind(vector<int> &v_black, vector<int> &v_white){
int b_points=0, w_points=0;
vector<int>::iterator ite;
if ((ite=find(v_black.begin(),v_black.end(),3))!=v_black.end())
b_points=ite-v_black.begin()+2;
if ((ite=find(v_white.begin(),v_white.end(),3))!=v_white.end())
w_points=ite-v_white.begin()+2;
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
return true;
}
return false;
}

bool straight(vector<int> &v_black, vector<int> &v_white){
int b_points=0, w_points=0;
for(int i=0; i<9; i++){
if(v_black[i]==1){
if((v_black[i+1]==1) && (v_black[i+2]==1) && (v_black[i+3]==1) && (v_black[i+4]==1))
b_points=i+6;
break;
}
}
for(int i=0; i<9; i++){
if(v_white[i]==1){
if((v_white[i+1]==1) && (v_white[i+2]==1) && (v_white[i+3]==1) && (v_white[i+4]==1))
w_points=i+6;
break;
}
}
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
return true;
}
return false;
}

bool flush(vector<int> &v_black, vector<int> &s_black, vector<int> &v_white, vector<int> &s_white){
int b_points=0, w_points=0;
if (find(s_black.begin(),s_black.end(),5)!=s_black.end())
b_points=1;
if (find(s_white.begin(),s_white.end(),5)!=s_white.end())
w_points=1;
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
high_card(v_black,v_white);
return true;
}
return false;
}

bool full_house(vector<int> &v_black, vector<int> &v_white){
int b_points=0, w_points=0;
vector<int>::iterator ite;
if (((ite=find(v_black.begin(),v_black.end(),3))!=v_black.end()) && ((find(v_black.begin(),v_black.end(),2))!=v_black.end()))
b_points=ite-v_black.begin()+2;
if (((ite=find(v_white.begin(),v_white.end(),3))!=v_white.end()) && ((find(v_white.begin(),v_white.end(),2))!=v_white.end()))
w_points=ite-v_white.begin()+2;
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
return true;
}
return false;
}

bool four_of_a_kind(vector<int> &v_black, vector<int> &v_white){
int b_points=0, w_points=0;
vector<int>::iterator ite;
if ((ite=find(v_black.begin(),v_black.end(),4))!=v_black.end())
b_points=ite-v_black.begin()+2;
if ((ite=find(v_white.begin(),v_white.end(),4))!=v_white.end())
w_points=ite-v_white.begin()+2;
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
return true;
}
return false;
}

bool straight_flush(vector<int> &v_black, vector<int> &s_black, vector<int> &v_white, vector<int> &s_white){
int b_points=0, w_points=0;
if (find(s_black.begin(),s_black.end(),5)!=s_black.end()){
for(int i=0; i<9; i++){
if(v_black[i]==1){
if((v_black[i+1]==1) && (v_black[i+2]==1) && (v_black[i+3]==1) && (v_black[i+4]==1))
b_points=i+6;
break;
}
}
}
if (find(s_white.begin(),s_white.end(),5)!=s_white.end()){
for(int i=0; i<9; i++){
if(v_white[i]==1){
if((v_white[i+1]==1) && (v_white[i+2]==1) && (v_white[i+3]==1) && (v_white[i+4]==1))
w_points=i+6;
break;
}
}
}
if(b_points!=0 || w_points!=0){
if(b_points>w_points)
cout<<"Black wins."<<endl;
else if (w_points>b_points)
cout<<"White wins."<<endl;
else
cout<<"Tie."<<endl;
return true;
}
return false;
}

int main(){
map<char,int> values;
values['2']=0;values['3']=1;values['4']=2;values['5']=3;values['6']=4;
values['7']=5;values['8']=6;values['9']=7;values['T']=8;values['J']=9;
values['Q']=10;values['K']=11;values['A']=12;
map<char,int> suits;
suits['C']=0;suits['D']=1;suits['H']=2;suits['S']=3;
while (true){
if (feof(stdin))
return 0;
vector<int> v_black(13,0);
vector<int> s_black(4,0);
vector<int> v_white(13,0);
vector<int> s_white(4,0);
for(int i=0; i<5; i++){
string card;
cin>>card;
if (card=="")
return 0;
v_black[values[card]]++;
s_black[suits[card]]++;
}
for(int i=0; i<5; i++){
string card;
cin>>card;
v_white[values[card]]++;
s_white[suits[card]]++;
}
if(straight_flush(v_black,s_black,v_white,s_white))
continue;
if(four_of_a_kind(v_black,v_white))
continue;
if(full_house(v_black,v_white))
continue;
if(flush(v_black,s_black,v_white,s_white))
continue;
if(straight(v_black,v_white))
continue;
if(three_of_a_kind(v_black,v_white))
continue;
if(two_pairs(v_black,v_white))
continue;
if(one_pair(v_black,v_white))
continue;
high_card(v_black,v_white);
}
}
``````