131 - The Psychic Poker Player

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

Moderator: Board moderators

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Can anyone explain the problem....

Thanks..
Ami ekhono shopno dekhi...
HomePage

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Got Accepted. :D

Thanks...
Ami ekhono shopno dekhi...
HomePage

WingletE
New poster
Posts: 35
Joined: Sun Aug 13, 2006 1:34 pm
Location: Taipei, Taiwan
Contact:

Post by WingletE »

I got Compile Error, but my code works fine on my computer.
Could somebody tell me what in my code would cause Compile Error, please?
Thanks!

Code: Select all

Code deleted after Accepted!

Note: Never use "void sort( iterator start, iterator end, StrictWeakOrdering cmp );" in c++ algorithm.

It has caused me countless of Compile Error.

sysabod
New poster
Posts: 2
Joined: Mon Jun 07, 2010 6:04 pm

131 got WA,still wondering

Post by sysabod »

:oops:
i have checked my code times after times(quite certain that my logic should be right),still have no idea why it failed to be accepted,hope you guys help me out.

Code: Select all

#include<stdio.h>
#include<string.h>
//#define ONLINE_JUDGE
char hand[7][4];
char deck[7][4];
char temp[7][4];
char s[6];
int num=0,max;
char subset[35][6];
char res[][20]={"highest-card","one-pair","two-pairs","three-of-a-kind",\
"straight","flush","full-house","four-of-a-kind","straight-flush"};
void make_subset(int cur)
{
    if(cur==5)
        strcpy(subset[num++],s);
    else
    {
        s[cur]='0';
        make_subset(cur+1);
        s[cur]='1';
        make_subset(cur+1);
    }
}
void sort()
{
    int i,j;
    char s[4];
    for(i=0;i<4;i++)
        for(j=i+1;j<5;j++)
            if(strcmp(temp[i],temp[j])>0)
            {
                strcpy(s,temp[j]);
                strcpy(temp[j],temp[i]);
                strcpy(temp[i],s);
            }
}
int is_sf()
{
    int i;
    char ch=temp[0][1];
    for(i=1;i<5;i++)
        if(temp[i][1]!=ch)
            return 0;
    for(i=1;i<4;i++)
        if(temp[i+1][0]-temp[i][0]!=1)
            return 0;
    if(temp[1][0]-temp[0][0]==1)
        return 1;
    else if(temp[0][0]==1&&temp[4][0]==13)
        return 1;
    else
        return 0;
}
int is_four()
{
    int i,k=0,nus;
    for(i=0;i<=1;i++)
        if(temp[i][0]==temp[i+1][0]&&temp[i+1][0]==temp[i+2][0]&&\
            temp[i+2][0]==temp[i+3][0])
            return 1;
    return 0;
}
int is_full()
{
    if(temp[0][0]==temp[1][0]&&temp[2][0]==temp[3][0]&&temp[3][0]==temp[4][0])
        return 1;
    if(temp[3][0]==temp[4][0]&&temp[2][0]==temp[1][0]&&temp[0][0]==temp[1][0])
        return 1;
    return 0;
}
int is_flush()
{
    char ch;
    int i;
    ch=temp[0][1];
    for(i=0;i<5;i++)
        if(ch!=temp[i][1])
            return 0;
    return 1;
}
int is_straight()
{
    int i;
    for(i=1;i<4;i++)
        if(temp[i+1][0]-temp[i][0]!=1)
            return 0;
    if(temp[1][0]-temp[0][0]==1)
        return 1;
    else if(temp[0][0]==1&&temp[4][0]==13)
        return 1;
    else
        return 0;
}
int is_three()
{
    int i;
    for(i=0;i<=2;i++)
        if(temp[i][0]==temp[i+1][0]&&temp[i+1][0]==temp[i+2][0])
            return 1;
    return 0;
}
int is_two()
{
    int i,k=0;
    for(i=0;i<4;)
        if(temp[i][0]==temp[i+1][0])
        {
            k++;i=i+2;
        }
        else
            i++;
    if(k==2)
        return 1;
    else
        return 0;
}
int is_one()
{
    int i;
    for(i=0;i<4;i++)
        if(temp[i][0]==temp[i+1][0])
            return 1;
    return 0;
}

int decide(int cur)
{
    memcpy(temp,hand,sizeof(hand));
    int i,j=0;
    for(i=0;i<5;i++)
    {
        if(subset[cur][i]=='0')
            strcpy(temp[i],deck[j++]);
        if(temp[i][0]=='T')
            temp[i][0]=10;
        else if(temp[i][0]=='J')
            temp[i][0]=11;
        else if(temp[i][0]=='Q')
            temp[i][0]=12;
        else if(temp[i][0]=='K')
            temp[i][0]=13;
        else if(temp[i][0]=='A')
            temp[i][0]=1;
        else
            temp[i][0]=temp[i][0]-48;
    }
    sort();
    if(is_sf())
        return 8;
    else if(is_four())
        return 7;
    else if(is_full())
        return 6;
    else if(is_flush())
        return 5;
    else if(is_straight())
        return 4;
    else if(is_three())
        return 3;
    else if(is_two())
        return 2;
    else if(is_one())
        return 1;
    else 
        return 0;
}
int main()
{
#ifdef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    make_subset(0);
    while(scanf("%s",hand[0])==1)
    {
        int i=0;
        max=0;
        for(i=1;i<5;i++)
            scanf("%s",hand[i]);
        for(i=0;i<5;i++)
            scanf("%s",deck[i]);
        
        for(i=0;i<num;i++)
        {
            int t=decide(i);
            if(t>max)
                max=t;
        }
        printf("Hand: ");
        for(i=0;i<5;i++)
            printf("%s ",hand[i]);
        printf("Deck: ");
        for(i=0;i<5;i++)
            printf("%s ",deck[i]);
        printf("Best hand: %s\n",res[max]);

    }
    return 0;
}
PLUS:
  • i read one input case and write the corresponding output ,is it inappropriate to so,if it is,how can i resove this

lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

Re: 131 - The Psychic Poker Player

Post by lighted »

sysabod, don't read from file. As Sohel pointed problem description is not clear. :evil:

Input

Code: Select all

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

Code: Select all

Hand: TH JH QC QD QS Deck: QH KH AH 2S 6S Best hand: straight-flush
Hand: 2H 2S 3H 3S 3C Deck: 2D 3D 6C 9C TH Best hand: four-of-a-kind
Hand: 2H 2S 3H 3S 3C Deck: 2D 9C 3D 6C TH Best hand: full-house
Hand: 2H AD 5H AC 7H Deck: AH 6H 9H 4H 3C Best hand: flush
Hand: AC 2D 9C 3S KD Deck: 5S 4D KS AS 4C Best hand: straight
Hand: KS AH 2H 3C 4H Deck: KC 2C TC 2D AS Best hand: three-of-a-kind
Hand: AH 2C 9S AD 3C Deck: QH KS JS JD KD Best hand: two-pairs
Hand: 6C 9C 8C 2D 7C Deck: 2H TC 4C 9S AH Best hand: one-pair
Hand: 3D 5S 2H QD TD Deck: 6S KH 9H AD QH Best hand: highest-card
Hand: TH JH QC QD QS Deck: QH KH AH 2S 6S Best hand: straight-flush
Hand: 2D 3D 6C 9C TH Deck: 2H 2S 3H 3S 3C Best hand: full-house
Hand: 2D 9C 3D 6C TH Deck: 2H 2S 3H 3S 3C Best hand: full-house
Hand: AH 6H 9H 4H 3C Deck: 2H AD 5H AC 7H Best hand: flush
Hand: 5S 4D KS AS 4C Deck: AC 2D 9C 3S KD Best hand: two-pairs
Hand: KC 2C TC 2D AS Deck: KS AH 2H 3C 4H Best hand: three-of-a-kind
Hand: QH KS JS JD KD Deck: AH 2C 9S AD 3C Best hand: two-pairs
Hand: 2H TC 4C 9S AH Deck: 6C 9C 8C 2D 7C Best hand: flush
Hand: 6S KH 9H AD QH Deck: 3D 5S 2H QD TD Best hand: one-pair
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman

Post Reply

Return to “Volume 1 (100-199)”