## 451 - Poker Solitaire Evaluator

Moderator: Board moderators

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

### 451 - Poker

Could anyone help me with this problem ?
I try to solve this after when I solved problem 10315 (Poker Hands). I use the same checker function, but I got WA many times .... Is any trap (or traps) in this question ??

Thanks for help

Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany
Straight: the five cards of the hand may be sorted on rank so that an unbroken sequence of 5 ranks is formed and the hand does not qualify for any of the following.
--> There can be cycle through Ace. <--
That is AC, 2H, 4D, 3H, 5S forms a straight, as does JH, XD,QC, KD, AS and QC, KD, AS, 2H, 3D.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Thx Adrian, but I know that and still WA ....
I found also that I have old version of description , in which ten was T not X .... but I got WA too ....
Does anyone other tricks ??

wangnoon
New poster
Posts: 7
Joined: Wed Jul 31, 2002 3:20 pm
Location: korea
Contact:

### Pls help me! Problem - 451. Poker Solitaire Evaluator.

I'm solved "Poker Solitaire Evaluator" Problem.
But i got WA..
but I can't find the bug.

This is C++ Code.

[cpp]
#include <iostream.h>
class poker {
public:
char suja;
char munja;
};
poker po[5][5];
int posu[9];int sp(class poker sm[5]);
int fc(class poker sm[5]);
int fh(class poker sm[5]);
int pl(class poker sm[5]);
int st(class poker sm[5]);
int tr(class poker sm[5]);
int tp(class poker sm[5]);
int op(class poker sm[5]);
int np(class poker sm[5]);
void input();
void output();
void process();
void main()
{
input();
process();
output();
}
void input()
{
int i,j;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
cin>>po[j].suja>>po[j].munja;
}
void process()
{
poker temp[5];
int i;

for(i=0;i<5;i++)
{
// cin>>temp[0].suja>>temp[0].munja>>temp[1].suja;
// cin>>temp[1].munja>>temp[2].suja>>temp[2].munja;
// cin>>temp[3].suja>>temp[3].munja>>temp[4].suja>>temp[4].munja;
temp[0]=po[0];
temp[1]=po[1];
temp[2]=po[2];
temp[3]=po[3];
temp[4]=po[4];
if(sp(temp)==1)
posu[8]++;
else if(fc(temp)==1)
posu[7]++;
else if(fh(temp)==1)
posu[6]++;
else if(pl(temp)==1)
posu[5]++;
else if(st(temp)==1)
posu[4]++;
else if(tr(temp)==1)
posu[3]++;
else if(tp(temp)==1)
posu[2]++;
else if(op(temp)==1)
posu[1]++;
else if(np(temp)==1)
posu[0]++;
}
for(i=0;i<5;i++)
{
temp[0]=po[0];
temp[1]=po[1];
temp[2]=po[2];
temp[3]=po[3][i];
temp[4]=po[4][i];
if(sp(temp)==1)
posu[8]++;
else if(fc(temp)==1)
posu[7]++;
else if(fh(temp)==1)
posu[6]++;
else if(pl(temp)==1)
posu[5]++;
else if(st(temp)==1)
posu[4]++;
else if(tr(temp)==1)
posu[3]++;
else if(tp(temp)==1)
posu[2]++;
else if(op(temp)==1)
posu[1]++;
else if(np(temp)==1)
posu[0]++;
}
}
void output()
{
int i;
for(i=0;i<8;i++)
cout<<posu[i]<<", ";
cout<<posu[8]<<endl;
}
int sp(class poker sm[])
{
if(st(sm) && pl(sm))
return 1;
return 0;
}
int fc(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
for(i=0;i<15;i++)
if(gasu[i]==4)
return 1;

return 0;
}
int fh(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==2)
flag=1;
else if(gasu[i]==3)
flag1=1;
if(flag==1 && flag1==1)
return 1;

return 0;
}
int pl(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
{
if( sm[i].munja == 'S')
gasu[1]++;
if( sm[i].munja == 'H')
gasu[2]++;
if( sm[i].munja == 'D')
gasu[3]++;
if( sm[i].munja == 'C')
gasu[4]++;
}
for(i=0;i<5;i++)
if(gasu[i]==5)
return 1;
return 0;
}
int st(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
for(i=0;i<15;i++)
if(gasu[i]==1)
if(gasu[i+1]==1 && gasu[i+2]==1 && gasu[i+3]==1 && gasu[i+4]==1)
return 1;
return 0;
}
int tr(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[14]++;
gasu[1]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==3)
return 1;
return 0;
}
int tp(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==2&& flag==0)
flag=1;
else if(gasu[i]==2 && flag==1)
flag1=1;
if(flag==1 && flag1==1)
return 1;

return 0;

}
int op(class poker sm[5])
{
int gasu[15]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[14]++;
gasu[1]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
gasu[sm[i].suja-48]++;
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==2)
return 1;

return 0;
}
int np(class poker sm[5])
{
return 1;
}
[/cpp]

I want the bug, &#12641;_&#12641;

tokei
New poster
Posts: 5
Joined: Tue Aug 20, 2002 7:27 am
Did you handle the case that the straight could be as follows?

AH 2S JH QH KD

wangnoon
New poster
Posts: 7
Joined: Wed Jul 31, 2002 3:20 pm
Location: korea
Contact:

### I try. But I can not solve it. help me more

I try to solve with your help.
But I Can't solve problem with WA.
Help me Some more.

Modified source :

[cpp]
#include <iostream.h>
class poker {
public:
char suja;
char munja;
};
poker po[5][5];
int posu[9];
int sp(class poker sm[5]);
int fc(class poker sm[5]);
int fh(class poker sm[5]);
int pl(class poker sm[5]);
int st(class poker sm[5]);
int tr(class poker sm[5]);
int tp(class poker sm[5]);
int op(class poker sm[5]);
int np(class poker sm[5]);
void input();
void output();
void process();
void main()
{
input();
process();
output();
}
void input()
{
int i,j;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
cin>>po[j].suja>>po[j].munja;
}
void process()
{
poker temp[5];
int i;

for(i=0;i<5;i++)
{
temp[0]=po[0];
temp[1]=po[1];
temp[2]=po[2];
temp[3]=po[3];
temp[4]=po[4];
if(sp(temp)==1)
posu[8]++;
else if(fc(temp)==1)
posu[7]++;
else if(fh(temp)==1)
posu[6]++;
else if(pl(temp)==1)
posu[5]++;
else if(st(temp)==1)
posu[4]++;
else if(tr(temp)==1)
posu[3]++;
else if(tp(temp)==1)
posu[2]++;
else if(op(temp)==1)
posu[1]++;
else if(np(temp)==1)
posu[0]++;
}
for(i=0;i<5;i++)
{
temp[0]=po[0];
temp[1]=po[1];
temp[2]=po[2];
temp[3]=po[3][i];
temp[4]=po[4][i];
if(sp(temp)==1)
posu[8]++;
else if(fc(temp)==1)
posu[7]++;
else if(fh(temp)==1)
posu[6]++;
else if(pl(temp)==1)
posu[5]++;
else if(st(temp)==1)
posu[4]++;
else if(tr(temp)==1)
posu[3]++;
else if(tp(temp)==1)
posu[2]++;
else if(op(temp)==1)
posu[1]++;
else if(np(temp)==1)
posu[0]++;
}
}
void output()
{
int i;
for(i=0;i<8;i++)
cout<<posu[i]<<", ";
cout<<posu[8]<<endl;
}
int sp(class poker sm[])
{

if(st(sm) && pl(sm))
return 1;
return 0;
}
int fc(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
for(i=0;i<30;i++)
if(gasu[i]==4)
return 1;

return 0;
}
int fh(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
int flag=0,flag1=0;
for(i=0;i<30;i++)
if(gasu[i]==2)
flag=1;
else if(gasu[i]==3)
flag1=1;
if(flag==1 && flag1==1)
return 1;

return 0;
}
int pl(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
{
if( sm[i].munja == 'S')
gasu[1]++;
if( sm[i].munja == 'H')
gasu[2]++;
if( sm[i].munja == 'D')
gasu[3]++;
if( sm[i].munja == 'C')
gasu[4]++;
}
for(i=0;i<5;i++)
if(gasu[i]==5)
return 1;
return 0;
}
int st(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
for(i=0;i<30;i++)
if(gasu[i]==1)
if(gasu[i+1]==1 && gasu[i+2]==1 && gasu[i+3]==1 && gasu[i+4]==1)
return 1;
return 0;
}
int tr(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[14]++;
gasu[1]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==3)
return 1;
return 0;
}
int tp(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[1]++;
gasu[14]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==2&& flag==0)
flag=1;
else if(gasu[i]==2 && flag==1)
flag1=1;
if(flag==1 && flag1==1)
return 1;

return 0;

}
int op(class poker sm[5])
{
int gasu[30]={0,};
int i;
for(i=0;i<5;i++)
if(sm[i].suja=='A')
{
gasu[14]++;
gasu[1]++;
}
else if(sm[i].suja=='X')
gasu[10]++;
else if(sm[i].suja=='J')
gasu[11]++;
else if(sm[i].suja=='Q')
gasu[12]++;
else if(sm[i].suja=='K')
gasu[13]++;
else
{
gasu[sm[i].suja-48]++;
gasu[sm[i].suja-48+13]++;
}
int flag=0,flag1=0;
for(i=0;i<15;i++)
if(gasu[i]==2)
return 1;

return 0;
}
int np(class poker sm[5])
{
return 1;
}
[/cpp]

Thank.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

### 451 - Poker Solitaire Evaluator

Could anyone tel me, why this code causes WA ??
I'm really frustrated, beacause I solve other poker problem (and I use the same algorithm) ......

Best regards
Dominik Michniewski

Code: Select all

``````I cut it off, because it's now a spoiler :(
``````
Last edited by Dominik Michniewski on Fri Feb 28, 2003 12:17 pm, edited 1 time in total.

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
Hi,

I Thinks this problem is multiple input problem.
The input should be like this:

2 <-- The number of test cases
<-- A blank line
3 <-- First data set
<-- A blank line
3 <-- Second data set.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
scanf() avoids blank and empty lines, so this code correct handle multiple input ... I think, that error must be somewhere else, but I don't imagine where ...

Dominik Michniewski
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
Hi, Dominik..

Code: Select all

``````input:
2

AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
XH 3C XC XS 8C

AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
XH 3C XC XS 8C``````

Code: Select all

``````Your output:
1, 1, 2, 1, 1, 1, 1, 1, 1

1, 1, 2, 1, 1, 1, 1, 1, 1``````

Code: Select all

``````The Output should be :
1, 1, 2, 1, 1, 1, 1, 1, 1
1, 1, 2, 1, 1, 1, 1, 1, 1
1, 1, 2, 1, 1, 1, 1, 1, 1

1, 1, 2, 1, 1, 1, 1, 1, 1
1, 1, 2, 1, 1, 1, 1, 1, 1``````
RS.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Hmmm ....
If I see correct (but I don't find it in problem specs) one part of input could be build with more than one deck ????????
It's no fair

Try this and maybe got accepted )
Thanks Red Scorpion for help )

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
I change my reading part to this: (in place of for loop with scanf() and Convert() ):

Code: Select all

``````		while(gets(line) != NULL)
{
if(line[0] == 0) break;
j = 0;
do
{
sscanf(line,"%s %s %s %s %s",c1,c2,c3,c4,c5);
all[j + 0] = Convert(c1);
all[j + 1] = Convert(c2);
all[j + 2] = Convert(c3);
all[j + 3] = Convert(c4);
all[j + 4] = Convert(c5);
j += 5;
if(j < 25) gets(line);
}
while(j < 25);
....
``````
But still got WA. I got now the same result as yours Red Scorpion. Some other thoughts ? Maybe I did something wrong ? Maybe there are input with less than five cards in one line ? Could anyone tell something about it ?

Best regards
Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Red Scorpion
Experienced poster
Posts: 192
Joined: Sat Nov 30, 2002 5:14 am
HI,

Code: Select all

``````Another sample input:
1

5S 2S 3S 4S 7S
AS 2S 3S 4S 5S
5S 6S 7S 8S 9S
JS 5S 6S 7S 8S
KS JS QS AS JS

0, 0, 0, 0, 0, 9, 0, 0, 1

My Output:
0, 0, 0, 0, 0, 8, 0, 0, 2``````
RS.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Red Scorpion, you should be guru instead of me :D:D:D

Code: Select all

``````   for(i=1;i<5;i++) if(x[i-1] != x[i] + 1) break;
if(i >= 5) straight = 1;
``````
should be

Code: Select all

``````   for(i=1;i<5;i++) if(x[i] != x[i-1] + 1) break;
if(i >= 5) straight = 1;
``````
Thanks all for help and best luck for every person in this site especialy for Red Scorpion and Adrian Kuegel

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Taneem
New poster
Posts: 6
Joined: Thu Jun 05, 2003 6:26 pm
Location: Arkansas, USA

### #10315: Poker Hands

Hey Dominik:

Regarding problem #10315-Poker Hands. Is this how you solve it, like you start off with "straight flush" and work your way through to "pair". In case of a tie or if none of these above work, you compare the card for the "high card".

I was wondering if there is any other way to solve this problem, like is there anyway to use a numeric value to find out who wins? I was told by someone that there is a way to do it by using a single numeric value of each poker hand and do a comparison on that.