Page 1 of 2
451 - Poker
Posted: Mon Jul 15, 2002 5:15 pm
by Dominik Michniewski
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
Posted: Mon Jul 15, 2002 7:40 pm
by Adrian Kuegel
Read this:
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.
Posted: Tue Jul 16, 2002 7:58 am
by Dominik Michniewski
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 ??
Pls help me! Problem - 451. Poker Solitaire Evaluator.
Posted: Mon Oct 07, 2002 12:50 pm
by wangnoon
I'm solved "Poker Solitaire Evaluator" Problem.
But i got WA..
but I can't find the bug.
please help me
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, ㅡ_ㅡ

Posted: Mon Oct 07, 2002 4:28 pm
by tokei
Did you handle the case that the straight could be as follows?
AH 2S JH QH KD
I try. But I can not solve it. help me more
Posted: Wed Oct 09, 2002 3:35 pm
by wangnoon
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.
451 - Poker Solitaire Evaluator
Posted: Thu Feb 06, 2003 2:15 pm
by Dominik Michniewski
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 :(
Posted: Tue Feb 18, 2003 4:04 am
by Red Scorpion
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.

Posted: Tue Feb 25, 2003 2:11 pm
by Dominik Michniewski
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
Posted: Fri Feb 28, 2003 9:01 am
by Red Scorpion
Hi, Dominik..
Code: Select all
input:
2
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
XH 3C XC XS 8C
AS 2S 3S 4S 5S
AC 2H 3H 5C 4C
AH 2D KC KH 5D
AD 3D KD 9D 8D
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.

Posted: Fri Feb 28, 2003 9:12 am
by Dominik Michniewski
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
Posted: Fri Feb 28, 2003 9:44 am
by Dominik Michniewski
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
Posted: Fri Feb 28, 2003 11:29 am
by Red Scorpion
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
Your output:
0, 0, 0, 0, 0, 9, 0, 0, 1
My Output:
0, 0, 0, 0, 0, 8, 0, 0, 2
Your Output still wrong!
RS.

Posted: Fri Feb 28, 2003 12:09 pm
by Dominik Michniewski
Red Scorpion, you should be guru instead of me

:D:D:D
I made a silly mistake : instead of
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
#10315: Poker Hands
Posted: Tue Jun 24, 2003 12:03 am
by Taneem
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.
I appreciate your help.
Thanks.