## 600 - A Duckpin Tournament

Moderator: Board moderators

ec3_limz
Learning poster
Posts: 79
Joined: Thu May 23, 2002 3:30 pm
Location: Singapore

### 600 - A Duckpin Tournament

Couldn't find any mistakes in this code. Tested with many test cases and all ran perfectly, but I still get a WA from the judge. Please help.

[cpp]#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const int NOSCORE=16843009;

struct {
char name[11];
int sc[3][30]; // score for each try
}
guy[4];
int nguy;

inline int max3(int a,int b,int c) {
return a>b?(a>c?a:c):(b>c?b:c);
}

int nextframe(int scores[12][3],int last) {
int i,j,sum;
for (i=last;i<12;i++) {
if (scores[0]<0 || scores[1]<0 || scores[2]<0)
continue;
sum=0;
for (j=0;j<3&&scores[j]!=NOSCORE;j++)
sum+=scores[j];
if (sum<10)
return i;
}
}

int *sequence(int scores[12][3]) {
int *rv=new int[30];
int i,j,p;

memset(rv,1,sizeof(int)*30); // default to NOSCORE
p=0;
for (i=0;i<12;i++)
for (j=0;j<3&&scores[j]!=NOSCORE;j++)
rv[p++]=scores[j];

return rv;
}

bool input() {
char line[256];
char *tok;
int scores[12][3],i,j,k,q;

gets(line);
if ((nguy=atoi(line))<1)
return false;

gets(line);
i=0;
for (tok=strtok(line," ");tok!=NULL;tok=strtok(NULL," "))
strcpy(guy[i++].name,tok);

for (j=0;j<3;j++)
for (i=0;i<nguy;i++) {
memset(scores,1,sizeof(scores)); // default to NOSCORE
for (k=0;k<3;k++) {
gets(line);
q=-1;
for (tok=strtok(line," ");tok!=NULL;tok=strtok(NULL," ")) {
q=nextframe(scores,q+1);
scores[q][k]=atoi(tok);
}
}
memcpy(guy.sc[j],sequence(scores),sizeof(guy.sc[j]));
}

gets(line);
return true;
}

void process() {
int nframe,frame,ntry,total[4][3],max,maxp;
int i,j,k,l;

// print score chart
memset(total,0,sizeof(total));
for (j=0;j<3;j++)
for (i=0;i<nguy;i++) {
printf("%-10s",guy.name);

frame=0;
ntry=0;
nframe=0;
for (k=0;k<30&&guy[i].sc[j][k]!=NOSCORE;k++) {
if (guy[i].sc[j][k]<0)
ntry=3;
else {
frame+=guy[i].sc[j][k];
ntry++;
}
if (frame>=10&&nframe<10) {
for (l=0;l<3-ntry;l++) {
if (guy[i].sc[j][k+l+1]<0)
break;
frame+=guy[i].sc[j][k+l+1];
}
ntry=3;
}
if (ntry>=3) {
printf("%4d",(total[i][j]+=frame));
frame=0;
ntry=0;
nframe++;
}
}

printf("\n");
}

// get highest series score
max=0;
for (i=0;i<nguy;i++)
if (max<total[i][0]+total[i][1]+total[i][2]) {
max=total[i][0]+total[i][1]+total[i][2];
maxp=i;
}
printf("%s has the high series score of %d.\n",guy[maxp].name,max);

// get highest game score
max=0;
for (i=0;i<nguy;i++)
if (max<max3(total[i][0],total[i][1],total[i][2])) {
max=max3(total[i][0],total[i][1],total[i][2]);
maxp=i;
}
printf("%s has the high game score of %d.\n",guy[maxp].name,max);

printf("\n");
}

int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

while (input())
process();

return 0;
}
[/cpp]

Yu Fan
New poster
Posts: 26
Joined: Thu Nov 13, 2003 3:52 am

### 600 WA

I couldnt find what wrong with it;
and even cant understand the input form;
i guess the three tries are right justifed but i'm not sure

Code: Select all

``````#include <stdio.h>
#include <stdlib.h>
#include <string.h>
inline bool num(char p) {
return (p>='0'&&p<='9');
}
char t[3][50]={0};
int score[36];
int toscore(int i,int j) {
if(!num(t[i][j]))
return -2;
while(num(t[i][j-1]))
j--;
if(t[i][j-1]=='-')
j--;
int tp=atoi(&t[i][j]);
return (tp<0)?(-1):tp;
}
void convert() {
int j,m=0;
for(j=1;t[0][j];j++)
if(num(t[0][j])&&!num(t[0][j+1])) {
score[3*m]=toscore(0,j);
score[3*m+1]=toscore(1,j);
score[3*m+2]=toscore(2,j);
m++;
}
}
void test() {
int j;
for(j=0;j<36;j+=3)
if(score[j]>-2)
printf("%3d",score[j]);
else
printf("   ");
printf("\n");
for(j=1;j<36;j+=3)
if(score[j]>-2)
printf("%3d",score[j]);
else
printf("   ");
printf("\n");
for(j=2;j<36;j+=3)
if(score[j]>-2)
printf("%3d",score[j]);
else
printf("   ");
printf("\n");
}
int main() {
int n,i,j,k,jj;
char name[4][20],tmp[10];
int high_game_name,high_game_score;
int high_series_name,high_series_score;
int frame[20];
int series[20];
while(scanf("%d",&n)&&n) {
high_game_score=high_series_score=-1;
for(i=0;i<n;i++) {
scanf("%s",&name[i]);
series[i]=0;
}
gets(tmp);
for(k=0;k<3;k++) {
for(i=0;i<n;i++) {
for(j=0;j<36;j++)
score[j]=-2;
for(j=0;j<50;j++)
t[0][j]=t[1][j]=t[2][j]=0;

gets(t[0]+1);
gets(t[1]+1);
gets(t[2]+1);
convert();
for(j=0;j<10;j++) {
frame[j]=score[3*j];
if(frame[j]<0) {
frame[j]=0;
continue;
}
if(frame[j]==10) {
for(jj=3*j+1;score[jj]==-2;jj++);
if(score[jj]<0)
continue;
frame[j]+=score[jj++];
for(;score[jj]==-2;jj++);
if(score[jj]>0)
frame[j]+=score[jj];
continue;
}
if(score[3*j+1]<0)
continue;
frame[j]+=score[3*j+1];
//					while(frame[j]>10)
//				    printf("xxxxxxxxxxxxxxxxxx");

if(frame[j]==10) {
for(jj=3*j+2;score[jj]==-2;jj++);
if(score[jj]>0)
frame[j]+=score[jj];
continue;
}
if(score[3*j+2]>0)
frame[j]+=score[3*j+2];
}
printf("%-10s%4d",name[i],frame[0]);
for(j=1;j<10;j++)
printf("%4d",frame[j]+=frame[j-1]);
printf("\n");
series[i]+=frame[9];
if(frame[9]>high_game_score) {
high_game_score=frame[9];
high_game_name=i;
}
}
}
for(i=0;i<n;i++)
if(high_series_score<series[i]) {
high_series_name=i;
high_series_score=series[i];
}
printf("%s has the high series score of %d.\n%s has the high game score of %d.\n",name[high_series_name],high_series_score,name[high_game_name],high_game_score);
gets(tmp);
}
return 0;
}``````

dmc
New poster
Posts: 5
Joined: Mon Dec 19, 2005 7:05 pm

### 600

I need some test cases for 600 task. thanks for all

luz019
New poster
Posts: 3
Joined: Mon Dec 18, 2006 4:19 am
Me toooo! Still getting runtime error

kogorman
New poster
Posts: 14
Joined: Sat Dec 02, 2006 6:58 am

### 600 WA

I'd like some more test cases too. Here is mine, it's just
one in addition to the one in the problem, but it was a
big help. If anyone uses this, I'd appreciate your posting

++ kevin

3
Tim Jim Bob
5 7 8 5 10 10 10 8 9 10 10 10 (scores for Tim's first game)
5 2 1 4 1 0
0 1 1 1 1
10 10 9 8 9 9 10 9 9 9 8 (scores for Jim's first game)
1 1 1 0 1 1 1
1 1
7 6 8 9 -10 8 9 8 10 10 8 1 (scores for Bob's first game)
3 2 2 1 1 1 1
2 1 1
0 8 8 8 9 7 6 -6 7 9 (scores for the second game)
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
5 7 10 9 8 9 10 7 8 9 7
5 3 1 2 1 -3 2 1 (blank line shows no 3rd
tries were used in this game)
9 8 9 8 9 7 10 9 9 9
1 1 1 2 1 2 0 1 0
1 1 1 1
5 6 7 8 9 10 10 -10 10 10 10 10 (scores for the third game)
4 2 3 1 1
0 2 1
8 7 6 10 9 9 10 7 8 6
2 2 3 1 0 3 1 3
1 0 1 1 1
9 8 9 9 9 8 10 10 10 8
1 2 1 1 1 2 1
1
#
3
Dick Harry Jared
10 10 10 10 10 10 10 10 10 10 10 10

10 10 10 10 10 10 10 10 10 10 5 5

10 10 10 10 10 10 10 10 10 5 5
5

10 10 10 10 10 10 10 10 10 5
0
5
10 1 3 10 10 10 10 10 5 5
0 5 0 0
2 2 5 5
10 10 10 10 10 10 10 10 5 5
5 0
5
10 10 10 10 10 10 10 10 5 5 5
0 5
5
10 5 10 10 10 10 10 10 5 5 5
5 0 5
5
10 5 5 10 10 10 10 10 5 5 5
5 1 0 5
4 5
#
0
Kevin

luz019
New poster
Posts: 3
Joined: Mon Dec 18, 2006 4:19 am
kogorman

I tried your additional test case and even count it myself and i got corresponding output:

Dick 30 60 90 120 150 180 210 240 270 300
Harry 30 60 90 120 150 180 210 240 265 285
Jared 30 60 90 120 150 180 210 235 255 270
Dick 30 60 90 120 150 180 210 235 250 260
Harry 11 14 24 54 84 114 139 154 164 174
Jared 30 60 90 120 150 180 205 225 240 250
Dick 30 60 90 120 150 180 205 220 230 245
Harry 20 40 70 100 130 160 185 200 210 225
Jared 20 35 45 75 105 135 160 175 185 200
Dick has the high series score of 805.
Jared has the high game score of 300.

Here are mine test cases. Most of them are only variations to the one in the problem but the first case with one player should consists of some tricky input, i hope

1
Tim
0 0 0 0 0 0 0 0 0 -1
0 0 0 0 1 1 10 -1 1
0 1 10 -1 0 1 -1
1 1 1 5 1 1 10 10 -1 10 5 -2
0 1 1 5 -1 1
0 0 1 -1
-10 10 8 10 -8 10 10 8 10 10 -2
-2 2

#
2
Benny Kozak
5 7 8 5 10 10 10 8 9 10 10 10
5 2 1 4 1 0
0 1 1 1 1
10 10 9 8 9 9 10 9 9 9 8
1 1 1 0 1 1 1
1 1
10 10 9 8 9 9 10 9 9 9 8
1 1 1 0 1 1 1
1 1
0 8 8 8 9 7 6 -6 7 9
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
5 7 10 9 8 9 10 7 8 9 7
5 3 1 2 1 -3 2 1

9 8 9 8 9 7 10 9 9 9
1 1 1 2 1 2 0 1 0
1 1 1 1
#
3
Tim Jim Denny
5 7 8 5 10 10 10 8 9 10 10 10
5 2 1 4 1 0
0 1 1 1 1
10 10 9 8 9 9 10 9 9 9 8
1 1 1 0 1 1 1
1 1
7 6 8 9 -10 8 9 8 10 10 8 1
3 2 2 1 1 1 1
2 1 1
0 8 8 8 9 7 6 -6 7 9
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
5 7 10 9 8 9 10 7 8 9 7
5 3 1 2 1 -3 2 1

9 8 9 8 9 7 10 9 9 9
1 1 1 2 1 2 0 1 0
1 1 1 1
5 6 7 8 9 10 10 -10 10 10 10 10
4 2 3 1 1
0 2 1
8 7 6 10 9 9 10 7 8 6
2 2 3 1 0 3 1 3
1 0 1 1 1
9 8 9 9 9 8 10 10 10 8
1 2 1 1 1 2 1
1
#
4
Tim Jim Kevin David
5 7 8 5 10 10 10 8 9 10 10 10
5 2 1 4 1 0
0 1 1 1 1
10 10 9 8 9 9 10 9 9 9 8
1 1 1 0 1 1 1
1 1
7 6 8 9 -10 8 9 8 10 10 8 1
3 2 2 1 1 1 1
2 1 1
0 8 8 8 9 7 6 -6 7 9
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
5 7 10 9 8 9 10 7 8 9 7
5 3 1 2 1 -3 2 1

9 8 9 8 9 7 10 9 9 9
1 1 1 2 1 2 0 1 0
1 1 1 1
5 6 7 8 9 10 10 -10 10 10 10 10
4 2 3 1 1
0 2 1
8 7 6 10 9 9 10 7 8 6
2 2 3 1 0 3 1 3
1 0 1 1 1
9 8 9 9 9 8 10 10 10 8
1 2 1 1 1 2 1
1
0 8 8 8 9 7 6 -6 7 9
6 1 2 1 0 1 3 3 0
3 0 1 1 1 0 0
10 10 9 8 9 9 10 9 9 9 8
1 1 1 0 1 1 1
1 1
8 7 6 10 9 9 10 7 8 6
2 2 3 1 0 3 1 3
1 0 1 1 1
#
0

And here is my output for this input. I counted it myself too (well, most of it }) so it should be allright.

Tim 0 1 11 11 12 14 24 24 25 25
Tim 1 3 6 17 18 20 40 50 50 65
Tim 0 18 26 36 36 64 84 104 124 134
Tim has the high series score of 224.
Tim has the high game score of 134.

Benny 17 26 36 46 76 104 123 133 143 173
Kozak 29 49 67 77 96 106 126 145 164 182
Benny 29 49 67 77 96 106 126 145 164 182
Kozak 9 18 36 46 56 65 74 74 93 102
Benny 17 37 57 75 94 114 131 138 157 174
Kozak 18 28 46 65 82 92 111 121 140 150
Benny has the high series score of 529.
Kozak has the high game score of 182.

Tim 17 26 36 46 76 104 123 133 143 173
Jim 29 49 67 77 96 106 126 145 164 182
Denny 16 26 45 55 55 65 83 93 121 140
Tim 9 18 36 46 56 65 74 74 93 102
Jim 17 37 57 75 94 114 131 138 157 174
Denny 18 28 46 65 82 92 111 121 140 150
Tim 9 19 37 47 67 87 97 97 127 157
Jim 17 27 36 56 75 85 105 123 133 143
Denny 18 37 56 75 93 113 143 171 190 200
Jim has the high series score of 499.
Denny has the high game score of 200.

Tim 17 26 36 46 76 104 123 133 143 173
Jim 29 49 67 77 96 106 126 145 164 182
Kevin 16 26 45 55 55 65 83 93 121 140
David 9 18 36 46 56 65 74 74 93 102
Tim 17 37 57 75 94 114 131 138 157 174
Jim 18 28 46 65 82 92 111 121 140 150
Kevin 9 19 37 47 67 87 97 97 127 157
David 17 27 36 56 75 85 105 123 133 143
Tim 18 37 56 75 93 113 143 171 190 200
Jim 9 18 36 46 56 65 74 74 93 102
Kevin 29 49 67 77 96 106 126 145 164 182
David 17 27 36 56 75 85 105 123 133 143
Tim has the high series score of 547.
David has the high game score of 200.

The question is, why im still getting that damn WA? I think, i don't understand well to this sentence in the output part of te problemset:
"No two players will get the same high score."

Im not speaking english well so im sorry about that.
Now, how the hell im going to figure out which of them will get that high score if two players have it the same? I solve this problem this way : the first player in the frame summary with the highest score(game or series) is stored into variable and if there is no larger number at other players following, the player who has that highest score is winner.
Maybe im totaly mistaken in this thing, so I hope someone will help me

kogorman
New poster
Posts: 14
Joined: Sat Dec 02, 2006 6:58 am
I think the statement means that there will NOT be duplicates.

I'm starting to worry about a "-0" in the input. It would correspond to a fault when no pins were knocked over,
so it would make sense in terms of a real game. And
normal input conversion would not catch it. Nasty.
Kevin

kogorman
New poster
Posts: 14
Joined: Sat Dec 02, 2006 6:58 am
Well, I changed all "-0" to "-1" and it still did not work.
I'm about to give up on 600.
Kevin

luz019
New poster
Posts: 3
Joined: Mon Dec 18, 2006 4:19 am
Well, -0 is really nasty. Maybe there is something I still can't see. This problem is crucial to me, because I need it done for one of my subjects on college - it's the last one I need
So i hope I can still do something about it. It's a pitty that I will be alone at this problem again but thank you kogorman for valuable informatin and maybe see you soon.

Bye people.

soth
New poster
Posts: 7
Joined: Tue Apr 17, 2007 1:22 am
I tried all test cases posted here and I get the -0 as a possible value in a test case too.
But I still got WA.
Some extra and rare test cases, please?
Thanks!!

soth
New poster
Posts: 7
Joined: Tue Apr 17, 2007 1:22 am
why I still get WA?

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am