462 - Bridge Hand Evaluator
Moderator: Board moderators
-
- 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".
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
![:-?](./images/smilies/icon_confused.gif)
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".
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!!!
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.
![:D](./images/smilies/icon_biggrin.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Oh... A really silly mistake in my if-the-else statements ![:P](./images/smilies/icon_razz.gif)
Fixed it and got ACC!![:lol:](./images/smilies/icon_lol.gif)
![:P](./images/smilies/icon_razz.gif)
Fixed it and got ACC!
![:lol:](./images/smilies/icon_lol.gif)
7th Contest of Newbies
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
Date: December 31st, 2011 (Saturday)
Time: 12:00 - 16:00 (UTC)
URL: http://uva.onlinejudge.org
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 );
}
}
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???
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???
i just solve the problem.
i think it is easy one with no tricky I/O.
Some inputs.
if this is not helpful.....
post your code.
i'll try to help.
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
post your code.
i'll try to help.
/* Sorry For Nothing */
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.
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 */
Hi,Cruzer:
I think these lines may exist a problem.Others seems OK.
Why didn't you add parentheses for these "if"?
if you haven't got AC yet,please try it.
Hope it helps.Bye~
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 ...
if you haven't got AC yet,please try it.
Hope it helps.Bye~