451 - Poker Solitaire Evaluator

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

Moderator: Board moderators

dserrano
New poster
Posts: 7
Joined: Tue Sep 17, 2002 2:39 am

Post by dserrano »

[quote="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.[/quote]


If this straight, QC, KD, AS, 2H, 3D. which one is the highest card? I think it

UFP2161
A great helper
Posts: 277
Joined: Mon Jul 21, 2003 7:49 pm
Contact:

Post by UFP2161 »

dserrano wrote:If this straight, QC, KD, AS, 2H, 3D. which one is the highest card?
If you're referring to 10315, a straight cannot wrap around the Ace. If 451, then that question has no relevance.
Taneem wrote:In case of a tie or if none of these above work, you compare the card for the "high card".
You have to follow the problem description when it's a tie. Most of the time, it's compare by next highest card as in traditional poker hand evaluation, but sometimes, it just stays a tie if it's the same hand. So reread the description carefully on ties.

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

Post by Dominik Michniewski »

print it as AKQ32 ...

Best regards
DM
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)

lovemagic
Learning poster
Posts: 52
Joined: Thu Oct 02, 2003 11:38 am

Post by lovemagic »

can somebody give me some test case?I passed the cases(multiple input) by Red Scorpion & it seems to me my code is right.but the OJ gives me WA.....

here is my code....

Code: Select all


#include <stdio.h>
#include <string.h>


int count[11];
char way[11][6][3];
char input[6][6][3],s[30];


int check_straight_flush(int i){
	int j,f=0,l;
	char t;
	int four[20];
	for(j=0;j<17;j++)four[j]=0;
	t=way[i][0][1];
	if(t==way[i][1][1] && t==way[i][2][1] && t==way[i][3][1] && t==way[i][4][1])
		f=1;
	if(f==0)return 0;	
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2'){four[1]++;four[14]++;}
		if(way[i][j][0]=='3'){four[2]++;four[15]++;}
		if(way[i][j][0]=='4'){four[3]++;four[16]++;}
		if(way[i][j][0]=='5')four[4]++;
		if(way[i][j][0]=='6')four[5]++;
		if(way[i][j][0]=='7')four[6]++;
		if(way[i][j][0]=='8')four[7]++;
		if(way[i][j][0]=='9')four[8]++;
		if(way[i][j][0]=='X')four[9]++;
		if(way[i][j][0]=='J')four[10]++;
		if(way[i][j][0]=='Q')four[11]++;
		if(way[i][j][0]=='K')four[12]++;
		if(way[i][j][0]=='A'){four[0]++;four[13]++;}
	}
	f=0;
	for(l=0;l<13 && !f;l++){
		if(four[l]==1 && four[l+1]==1 && four[l+2]==1 && four[l+3]==1 && four[l+4]==1)
			f=1;
	}
	return f;
}

int check_four_kind(int i){
	int j,f=0;
	int four[15];
	for(j=0;j<13;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2')four[0]++;
		if(way[i][j][0]=='3')four[1]++;
		if(way[i][j][0]=='4')four[2]++;
		if(way[i][j][0]=='5')four[3]++;
		if(way[i][j][0]=='6')four[4]++;
		if(way[i][j][0]=='7')four[5]++;
		if(way[i][j][0]=='8')four[6]++;
		if(way[i][j][0]=='9')four[7]++;
		if(way[i][j][0]=='X')four[8]++;
		if(way[i][j][0]=='J')four[9]++;
		if(way[i][j][0]=='Q')four[10]++;
		if(way[i][j][0]=='K')four[11]++;
		if(way[i][j][0]=='A')four[12]++;
	}
	for(j=0;j<13 && !f;j++)
		if(four[j]==4)f=1;
	return f;
}


int check_full_house(int i){
	int j,f=0;
	int four[15];
	for(j=0;j<13;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2')four[0]++;
		if(way[i][j][0]=='3')four[1]++;
		if(way[i][j][0]=='4')four[2]++;
		if(way[i][j][0]=='5')four[3]++;
		if(way[i][j][0]=='6')four[4]++;
		if(way[i][j][0]=='7')four[5]++;
		if(way[i][j][0]=='8')four[6]++;
		if(way[i][j][0]=='9')four[7]++;
		if(way[i][j][0]=='X')four[8]++;
		if(way[i][j][0]=='J')four[9]++;
		if(way[i][j][0]=='Q')four[10]++;
		if(way[i][j][0]=='K')four[11]++;
		if(way[i][j][0]=='A')four[12]++;
	}
	for(j=0;j<13;j++){
		if(four[j]==3){
			f=1;
			break;
		}
	}
	if(f==1){
		for(j=0;j<13;j++)
			if(four[j]==2){
				f=2;
				break;
			}
	}

	if(f==2)return 1;
	else return 0;
}

int check_flush(int i){
	int f=0;
	char t;
	t=way[i][0][1];
	if(t==way[i][1][1] && t==way[i][2][1] && t==way[i][3][1] && t==way[i][4][1])return 1;
	return 0;
}

int check_straight(int i){
	int j,f=0,l;
	int four[20];
	for(j=0;j<17;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2'){four[1]++;four[14]++;}
		if(way[i][j][0]=='3'){four[2]++;four[15]++;}
		if(way[i][j][0]=='4'){four[3]++;four[16]++;}
		if(way[i][j][0]=='5')four[4]++;
		if(way[i][j][0]=='6')four[5]++;
		if(way[i][j][0]=='7')four[6]++;
		if(way[i][j][0]=='8')four[7]++;
		if(way[i][j][0]=='9')four[8]++;
		if(way[i][j][0]=='X')four[9]++;
		if(way[i][j][0]=='J')four[10]++;
		if(way[i][j][0]=='Q')four[11]++;
		if(way[i][j][0]=='K')four[12]++;
		if(way[i][j][0]=='A'){four[0]++;four[13]++;}
	}
	for(l=0;l<13 && !f;l++){
		if(four[l]==1 && four[l+1]==1 && four[l+2]==1 && four[l+3]==1 && four[l+4]==1){
			f=1;
		}
	}
	return f;
}

int check_three_kind(int i){
	int j,f=0;
	int four[15];
	for(j=0;j<13;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2')four[0]++;
		if(way[i][j][0]=='3')four[1]++;
		if(way[i][j][0]=='4')four[2]++;
		if(way[i][j][0]=='5')four[3]++;
		if(way[i][j][0]=='6')four[4]++;
		if(way[i][j][0]=='7')four[5]++;
		if(way[i][j][0]=='8')four[6]++;
		if(way[i][j][0]=='9')four[7]++;
		if(way[i][j][0]=='X')four[8]++;
		if(way[i][j][0]=='J')four[9]++;
		if(way[i][j][0]=='Q')four[10]++;
		if(way[i][j][0]=='K')four[11]++;
		if(way[i][j][0]=='A')four[12]++;
	}

	for(j=0;j<13 && !f;j++)
		if(four[j]==3)f=1;
	return f;
}

int check_two_pair(int i){
	int j,f=0;
	int four[15];
	for(j=0;j<13;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2')four[0]++;
		if(way[i][j][0]=='3')four[1]++;
		if(way[i][j][0]=='4')four[2]++;
		if(way[i][j][0]=='5')four[3]++;
		if(way[i][j][0]=='6')four[4]++;
		if(way[i][j][0]=='7')four[5]++;
		if(way[i][j][0]=='8')four[6]++;
		if(way[i][j][0]=='9')four[7]++;
		if(way[i][j][0]=='X')four[8]++;
		if(way[i][j][0]=='J')four[9]++;
		if(way[i][j][0]=='Q')four[10]++;
		if(way[i][j][0]=='K')four[11]++;
		if(way[i][j][0]=='A')four[12]++;
	}
	for(j=0;j<13;j++)
		if(four[j]==2){
			f=j;
			break;
		}
	if(f==j){
		for(j=0;j<13;j++)
			if(j!=f && four[j]==2){
				f=2;
				break;
			}
	}
	if(f==2)return 1;
	else return 0;
}


int check_one_pair(int i){
	int j,f=0;
	int four[15];
	for(j=0;j<13;j++)four[j]=0;
	for(j=0;j<5;j++){
		if(way[i][j][0]=='2')four[0]++;
		if(way[i][j][0]=='3')four[1]++;
		if(way[i][j][0]=='4')four[2]++;
		if(way[i][j][0]=='5')four[3]++;
		if(way[i][j][0]=='6')four[4]++;
		if(way[i][j][0]=='7')four[5]++;
		if(way[i][j][0]=='8')four[6]++;
		if(way[i][j][0]=='9')four[7]++;
		if(way[i][j][0]=='X')four[8]++;
		if(way[i][j][0]=='J')four[9]++;
		if(way[i][j][0]=='Q')four[10]++;
		if(way[i][j][0]=='K')four[11]++;
		if(way[i][j][0]=='A')four[12]++;
	}
	for(j=0;j<13 && !f;j++)
		if(four[j]==2)f=1;
	return f;
}


int main(){
	int i,j,k,ks,t;
	scanf("%d",&ks);
	gets(s);
	gets(s);
	for(;ks>0;ks--){
		t=0;
		while(gets(s) && s[0]){
			sscanf(s,"%s %s %s %s %s",input[t][0],input[t][1],input[t][2],input[t][3],input[t][4]);
			t++;
			if(t==5){
				t=0;

				memset(count,0,sizeof(count));

				for(i=0;i<5;i++)
					for(j=0;j<5;j++)
						strcpy(way[i][j],input[i][j]);

				k=5;
				for(i=0;i<5;i++){
					for(j=0;j<5;j++){
						strcpy(way[k][j],input[j][i]);
					}
					k++;
				}

/*		for(i=0;i<10;i++){
			for(j=0;j<5;j++)
				printf(" %s",way[i][j]);
			printf("\n");
		}*/



				for(i=0;i<10;i++){		
					if(check_straight_flush(i)==1){
						count[8]++;
						continue;
					}
	
					if(check_four_kind(i)==1){
						count[7]++;
						continue;
					}
	
					if(check_full_house(i)==1){
						count[6]++;
						continue;
					}

					if(check_flush(i)==1){
						count[5]++;
						continue;
					}

					if(check_straight(i)==1){
						count[4]++;
						continue;
					}

					if(check_three_kind(i)==1){
						count[3]++;
						continue;
					}

					if(check_two_pair(i)==1){
						count[2]++;
						continue;
					}
	
					if(check_one_pair(i)==1){
						count[1]++;
						continue;
					}

					else 
						count[0]++;
				}

				printf("%d",count[0]);
				for(i=1;i<9;i++)
					printf(", %d",count[i]);
				printf("\n");
			}
		}
	
		if(ks!=1)printf("\n");
	}
	return 0;
}


khobaib

Post Reply

Return to “Volume 4 (400-499)”