## 462 - Bridge Hand 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

turboc
New poster
Posts: 2
Joined: Mon Dec 17, 2001 2:00 am
Contact:
Some thing seems wrong.
There are same cards in the 13 cards of a hand. How could I calc the point?
wyvmak
Experienced poster
Posts: 110
Joined: Thu Dec 13, 2001 2:00 am
For me, i don't understand which rules to follow. It has claimed to have "ignoring rule 5,6,7" but in the output, to evaluate the 17 points. it has taken into account of rule 5. isn't it a bit weird?

and it claimed to sort the S H D C, but at the same time telling me two possible inputs. why?
scottaugust
New poster
Posts: 18
Joined: Thu Jun 20, 2002 4:54 pm
Since it has been some time since these posts were made, these comments my be irrelevant, however here goes:

I had this problem accepted before it was re-judged, however not after - it perplexed me for a long time. However this is what I learned. The problem that I had was that before the problem was re-judged, a jack with more that 3 cards would stop a suit (I'm not sure if the problem description changed or the test data changed ).

Turboc:

Don't worry if there is duplicate cards or not, simply following the rules will solve the problem. There are only 13 cards for each input.

wyvmak:

There are two values that you need to calculate, a total point value and a no-trump point value. You use rules 5, 6 & 7 in the total point value, but not in the no-trump point value.

In the end of the example there are two possible outputs "bid c" and "bid d", however since you need to sort the result by suit, the only accepted output is "bid d".
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong

### 462 Bridge Hand Evaluator Plz help!

I'm getting WA in this qq. I think this qq is straightforward, yet......

Could anyone help me??!! Thx in advance!

P.S. I don't want to post my code here because it's rather long. However, I can sent you via PM. Plz help me!!!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Observer
Guru
Posts: 570
Joined: Sat May 10, 2003 4:20 am
Location: Hong Kong
Oh... A really silly mistake in my if-the-else statements

Fixed it and got ACC!
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Cruzer
New poster
Posts: 11
Joined: Thu Feb 10, 2005 4:18 am
Location: Waterloo, ON, Canada

### 462 weird WA

This one seems so easy, and yet I have WA for some reason. I've checked it over so many times and can't find the problem. Here is my code (sorry it's so long, but it should be straight-forward):

Code: Select all

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

main() {
char hand[13][4];   /* 13 cards - #/suit */
int score, no_trump_score;
int S_stopped, H_stopped, D_stopped, C_stopped; /* Flags for stopped suits */
int S_num, H_num, D_num, C_num; /* Number of each suit */
char bid[15];   /* Pass, bid suit, bid no trump */
int first_time = 1; /* Flag for first time through loop */
int i;

while( !feof(stdin) ){
/* Print \n if not first time through loop */
if( first_time == 0 ) {
printf("\n");
}
first_time = 0;

/* Initialization */
score = no_trump_score = S_stopped = H_stopped = D_stopped = C_stopped = S_num = H_num = D_num = C_num = 0;

/* Get input, Count cards in each suit as they are input */
for( i = 0; i < 13; i++ ) {
scanf("%s", hand[i]);
switch( hand[i][1] ) {
case 'S':   S_num++;
break;
case 'H':   H_num++;
break;
case 'D':   D_num++;
break;
case 'C':   C_num++;
break;
}
}

/* Apply rules 1-4 to score and no_trump_score, also finds stopped suits */
for( i = 0; i < 13; i++ ) {
/* Case: ACE */
if( hand[i][0] == 'A' ) {
/* Rule 1: Add 4 points */
score += 4;
no_trump_score += 4;

/* Stop suit */
switch( hand[i][1] ) {
case 'S':   S_stopped = 1;
break;
case 'H':   H_stopped = 1;
break;
case 'D':   D_stopped = 1;
break;
case 'C':   C_stopped = 1;
break;
}
}

/* Case: KING */
if( hand[i][0] == 'K' ) {
/* Rule 1: Add 3 points */
score += 3;
no_trump_score += 3;

/* Rule 2: Subtract 1 point if no other cards in this king's suit */
switch( hand[i][1] ) {
case 'S':   if( S_num == 1 )
score--;
no_trump_score--;
break;
case 'H':   if( H_num == 1 )
score--;
no_trump_score--;
break;
case 'D':   if( D_num == 1 )
score--;
no_trump_score--;
break;
case 'C':   if( C_num == 1 )
score--;
no_trump_score--;
break;
}

/* Stop suit if one other card of suit exists */
switch( hand[i][1] ) {
case 'S':   if( S_num > 1 )
S_stopped = 1;
break;
case 'H':   if( H_num > 1 )
H_stopped = 1;
break;
case 'D':   if( D_num > 1 )
D_stopped = 1;
break;
case 'C':   if( C_num > 1 )
C_stopped = 1;
break;
}
}

/* Case: QUEEN */
if( hand[i][0] == 'Q' ) {
/* Rule 1: Add 2 points */
score += 2;
no_trump_score += 2;

/* Rule 3: Subtract 1 point if less than 2 other cards in this queen's suit */
switch( hand[i][1] ) {
case 'S':   if( S_num < 3 )
score--;
no_trump_score--;
break;
case 'H':   if( H_num < 3 )
score--;
no_trump_score--;
break;
case 'D':   if( D_num < 3 )
score--;
no_trump_score--;
break;
case 'C':   if( C_num < 3 )
score--;
no_trump_score--;
break;
}

/* Stop suit if two other cards of suit exists */
switch( hand[i][1] ) {
case 'S':   if( S_num > 2 )
S_stopped = 1;
break;
case 'H':   if( H_num > 2 )
H_stopped = 1;
break;
case 'D':   if( D_num > 2 )
D_stopped = 1;
break;
case 'C':   if( C_num > 2 )
C_stopped = 1;
break;
}
}

/* Case: JACK */
if( hand[i][0] == 'J' ) {
/* Rule 1: Add 1 point */
score += 1;
no_trump_score += 1;

/* Rule 4: Subtract 1 point if less than 3 other cards in this jack's suit */
switch( hand[i][1] ) {
case 'S':   if( S_num < 4 )
score--;
no_trump_score--;
break;
case 'H':   if( H_num < 4 )
score--;
no_trump_score--;
break;
case 'D':   if( D_num < 4 )
score--;
no_trump_score--;
break;
case 'C':   if( C_num < 4 )
score--;
no_trump_score--;
break;
}
}
}

/* Apply rules 5-7 to score */
if( S_num == 2 )
score++;
else if( S_num == 1 || S_num == 0 )
score += 2;
if( H_num == 2 )
score++;
else if( H_num == 1 || H_num == 0 )
score += 2;
if( D_num == 2 )
score++;
else if( D_num == 1 || D_num == 0 )
score += 2;
if( C_num == 2 )
score++;
else if( C_num == 1 || C_num == 0 )
score += 2;

/* Find recommended bid */
/* Case: PASS */
if( score < 14 ) {
strcpy( bid, "PASS" );
}
/* Case: BID NO-TRUMP */
else if( no_trump_score >= 16 && S_stopped == 1 && H_stopped == 1 && D_stopped == 1 && C_stopped == 1 ) {
strcpy( bid, "BID NO-TRUMP" );
}
/* Case: BID SUIT */
else {
/* Find suit with highest num */
if( S_num >= H_num && S_num >= D_num && S_num >= C_num ) {
strcpy( bid, "BID S" );
}
else if( H_num > S_num && H_num >= D_num && H_num >= C_num ) {
strcpy( bid, "BID H" );
}
else if( D_num > S_num && D_num > H_num && D_num >= C_num ) {
strcpy( bid, "BID D" );
}
else {
strcpy( bid, "BID C" );
}
}

/* Print result for this hand */
printf( "%s", bid );
}
}
``````
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm

### 462 - Bridge Hand Evaluator

Hi, Guys I need your help!!!
The broblem is so simple that I writed it very fast, but I got WA all the time. But with 2 tests variants in example it works perfect.
Can somebody send INPUT/OUTPUT from AC program???
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm
Guys please, I really need to solve this problem...
I need only INPUT/OUTPUT from AC program...

I will become crazy, but i could not find mistake in code....
For it is perfect...
May be some special cases????
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm
Guys I really need to solve this problem... Can you tell me if I will post my code here where my logic is wrong. Because I can not find error, but still I ahve WA.
I can send you source via an e-mail. Or if you want just post it here on forum....
Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
i just solve the problem.
i think it is easy one with no tricky I/O.

Some inputs.

Code: Select all

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

outputs :

BID S
BID S
BID S
PASS
BID NO-TRUMP

``````
if this is not helpful.....
i'll try to help.
/* Sorry For Nothing */
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm
I test you INPUT/OUTPUT...So no error everything is correcty...but still WA.
Thanks for help. I send source code by e-mail to you( in your profile)...
I will wait for the abswer, thanks a lot
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm
Hello Sakib,

Where are you ??? Did you got my e-mail???

What you can say about code???
Can you allocate this crazy mistake????
I cant get it...
Sakib
New poster
Posts: 24
Joined: Fri Jan 28, 2005 5:27 pm
i dont really get your problem.
but i find something unusual.
when the end of file reaches your program output an extra output.
for example when i press ctrl + z after the sample input your program
output an extra "BID S".
which can cause WA!!!

i took input like this :

while(scanf("%s",s) == 1)
{
for(i=1;i<13;i++)scanf("%s",s);
}

try this.
your program seems ok except that.
Thanks.
/* Sorry For Nothing */
mihailss
New poster
Posts: 6
Joined: Wed Nov 23, 2005 10:35 pm
Hi,
I change the program by the way you write to me, but still WA again. So I am in big trouble. Can you send me your source code to my e-mail (you must have it, because I allready send one message to you.)

Really so easy problem, but I could not get my problem....
pineapple
Learning poster
Posts: 57
Joined: Fri Nov 03, 2006 3:33 pm
Hi,Cruzer:
I think these lines may exist a problem.Others seems OK.

Code: Select all

``````case 'S':
if( S_num == 1 )
score--;
no_trump_score--;
case ...

``````
Why didn't you add parentheses for these "if"?
if you haven't got AC yet,please try it.
Hope it helps.Bye~