Hi, my code gets all test cases passed in udebug but is still getting wa in oj.Please help!!!
#include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
int main(){
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
char arr[50];char csuit;
int err=0;
int i=0,tp;
int ncards[4];
while(gets(arr)){
bool invalidi=false;
bool stoped[4];
for(int j=0;j<4;j++){
ncards[j]=0;
stoped[j]=false;
}
tp=0;
//tp=0,ns=0,nc=0,nd=0,nh=0;
/*for(i=0;i<strlen(arr);i++){
printf("%c",arr);
}
printf("\n");
*/
for(i=0;i<strlen(arr);i++){
if(arr=='A')
tp+=4;
if(arr=='K')
tp+=3;
if(arr=='Q')
tp+=2;
if(arr=='J')
tp+=1;
if(arr=='S')
ncards[0]++;
if(arr=='C')
ncards[3]++;
if(arr=='H')
ncards[1]++;
if(arr=='D')
ncards[2]++;
}
/*for(int j=0;j<4;j++){
printf("%d \n",ncards[j]);
}*/
for(i=0;i<strlen(arr);i++){
if(arr=='K'){
csuit=arr[i+1];
if((csuit=='S' && ncards[0]==1) || (csuit=='H' && ncards[1]==1) || (csuit=='D' && ncards[2]==1) || (csuit=='C' && ncards[3]==1))
tp--;
}
if(arr[i]=='Q'){
csuit=arr[i+1];
//printf("\ncsuit %c ncards %d\n",csuit,ncards[2]);
if((csuit=='S' && ncards[0]<=2) || (csuit=='H' && ncards[1]<=2) || (csuit=='D' && ncards[2]<=2) || (csuit=='C' && ncards[3]<=2)){
tp--;
//printf("\n- hela\n");
}
}
if(arr[i]=='J'){
csuit=arr[i+1];
if((csuit=='S' && ncards[0]<=3) || (csuit=='H' && ncards[1]<=3) || (csuit=='D' && ncards[2]<=3) || (csuit=='C' && ncards[3]<=3))
tp--;
}
}
if(tp==0){
int c;
for(int j=0;j<4;j++)
if(ncards[j]==0)
c++;
if(c==4)
invalidi=true;
}
int ntscore=tp;
for(int j=0;j<4;j++){
if(ncards[j]==2)
tp++;
if(ncards[j]==0 || ncards[j]==1)
tp+=2;
}
if(invalidi)
break;
/*printf("tp for no trump %d\n",tp);
for(int j=0;j<4;j++)
printf("\n%d\n",ncards[j]);
*/
for(i=0;i<strlen(arr);i++){
if(arr[i]=='A'){
csuit=arr[i+1];
if(csuit=='S')
stoped[0]=true;
if(csuit=='H')
stoped[1]=true;
if(csuit=='D')
stoped[2]=true;
if(csuit=='C')
stoped[3]=true;
}
if(arr[i]=='K'){
csuit=arr[i+1];
if(csuit=='S' && ncards[0]>=2)
stoped[0]=true;
if(csuit=='H' && ncards[1]>=2)
stoped[1]=true;
if(csuit=='D' && ncards[2]>=2)
stoped[2]=true;
if(csuit=='C' && ncards[3]>=2)
stoped[3]=true;
}
if(arr[i]=='Q'){
csuit=arr[i+1];
if(csuit=='S' && ncards[0]>=3)
stoped[0]=true;
if(csuit=='H' && ncards[1]>=3)
stoped[1]=true;
if(csuit=='D' && ncards[2]>=3)
stoped[2]=true;
if(csuit=='C' && ncards[3]>=3)
stoped[3]=true;
}
}
bool allstoped=false;
int c=0;
for(int j=0;j<4;j++){
if(stoped[j])
c++;
}
if(c==4)
allstoped=true;
// printf("\n%d\n",stoped[j]);
//printf("%d tp\n %d nts",tp,ntscore);
if(tp<14){
if(err==0){
printf("PASS");
err=12;
}
else
printf("\nPASS");
}
else if((ntscore>=16) && allstoped){
if(err==0){
printf("BID NO-TRUMP");
err=12;
}
else
printf("\nBID NO-TRUMP");
}
else{
int h=0,index=0;
for(int j=0;j<4;j++){
if(ncards[j]>h){
h=ncards[j];
index=j;
}
}
if(index==0){
if(err==0){
printf("BID S");
err=12;
}
else
printf("\nBID S");
}
if(index==1){
if(err==0){
printf("BID H");
err=12;
}
else
printf("\nBID H");
}
//printf("BID H\n");
if(index==2){
if(err==0){
printf("BID D");
err=12;
}
else
printf("\nBID D");
}
//printf("BID D\n");
if(index==3){
if(err==0){
printf("BID C");
err=12;
}
else
printf("\nBID C");
}
// printf("BID C\n");
}
}
}
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
Return to “Volume 4 (400-499)”
Jump to
- Real Time Contests and Last Minute Information
- ↳ General
- ↳ Real Time Clarification
- ↳ Fixing Mistakes
- ↳ HOWTOs
- ↳ Bugs and suggestions
- New system
- ↳ FAQ
- ↳ Bugs and suggestions
- Let's make some programs!
- ↳ Other words
- ↳ Algorithms
- ↳ New features
- Help on the Problemset
- ↳ Volume 1 (100-199)
- ↳ Volume 2 (200-299)
- ↳ Volume 3 (300-399)
- ↳ Volume 4 (400-499)
- ↳ Volume 5 (500-599)
- ↳ Volume 6 (600-699)
- ↳ Volume 7 (700-799)
- ↳ Volume 8 (800-899)
- ↳ Volume 9 (900-999)
- ↳ Volume 10 (1000-1099)
- ↳ Volume 11 (1100-1199)
- ↳ Volume 12 (1200-1299)
- ↳ Volume 13 (1300-1399)
- ↳ Volume 14 (1400-1499)
- ↳ Volume 15 (1500-1599)
- ↳ Volume 16 (1600-1699)
- ↳ Volume 17 (1700-1799)
- ↳ Volume 100 (10000-10099)
- ↳ Volume 101 (10100-10199)
- ↳ Volume 102 (10200-10299)
- ↳ Volume 103 (10300-10399)
- ↳ Volume 104 (10400-10499)
- ↳ Volume 105 (10500-10599)
- ↳ Volume 106 (10600-10699)
- ↳ Volume 107 (10700-10799)
- ↳ Volume 108 (10800-10899)
- ↳ Volume 109 (10900-10999)
- ↳ Volume 110 (11000-11099)
- ↳ Volume 111 (11100-11199)
- ↳ Volume 112 (11200-11299)
- ↳ Volume 113 (11300-11399)
- ↳ Volume 114 (11400-11499)
- ↳ Volume 115 (11500-11599)
- ↳ Volume 116 (11600-11699)
- ↳ Volume 117 (11700-11799)
- ↳ Volume 118 (11800-11899)
- ↳ Volume 119 (11900-11999)
- ↳ Volume 120 (12000-12099)
- ↳ Volume 121 (12100-12199)
- ↳ Volume 122 (12200-12299)
- ↳ Volume 123 (12300-12399)
- ↳ Volume 124 (12400-12499)
- ↳ Volume 125 (12500-12599)
- ↳ Volume 126 (12600-12699)
- ↳ Volume 127 (12700-12799)
- ↳ Volume 128 (12800-12899)
- ↳ Volume 129 (12900-12999)
- ↳ Volume 130 (13000-13099)
- ↳ Volume 131 (13100-13199)
- Help on languages
- ↳ C
- ↳ C++
- ↳ Pascal
- ↳ Java
- Off Topic
- ↳ Off topic (General chit-chat)
- Category
- ↳ ACM ICPC Archive Board