## 584 - Bowling

Moderator: Board moderators

Sirso
New poster
Posts: 3
Joined: Tue Apr 19, 2005 1:50 am

### 584 - Bowling

I've tested all the games I could imagine and it works fine. Yet I keep getting WA.

Could someone please provide me with a sample input for this problem?

Thanks a lot!

leonardooo
New poster
Posts: 8
Joined: Sun Nov 28, 2004 9:26 am
Location: Campina Grande - PB / Brazil

### me too

I dont know why i am getting WA... somebody have inputs/outputs to broke my code?

here, my code.. in JAVA

Code: Select all

``````import java.util.StringTokenizer;

class Main {

public static void main(String[] args) {

StringBuffer sb = new StringBuffer();
boolean pula = false;

while(!input.equals("Game Over") ) {

int count = 0;
int score = 0;
int previous = 0;
int i = count;
int nFrame = 1;
int nRoll = 1;
int[] frames = new int[23];

StringTokenizer st = new StringTokenizer(input);
while(st.hasMoreTokens()) {

String chance = st.nextToken();
if( chance.equals("/") ) {
frames[count++] = 10 - previous;
} else if( chance.equals("X") ) {
frames[count++] = 10;
} else {
frames[count++] = Integer.parseInt(chance);
previous = frames[count-1];
}

i = count - 1;
score += frames[i];
if( i > 0 && frames[i-1] == 10 && nFrame < 11) score += frames[i]; // strike in last chance
if( i > 1 && frames[i-2] == 10 && nFrame < 11) score += frames[i]; // strike in previoous last chance
if( i > 1 && frames[i-1] + frames[i-2] == 10 && nFrame < 11) score += frames[i]; // spare in last chance
if( nFrame == 12 && nRoll == 1 && frames[i] == 10 && frames[i-1] == 10 ) score += frames[i]; // two strikes in bonus

if(frames[i] == 10 || nRoll == 2) { nFrame++; nRoll = 1; }
else { nRoll++; }

//stop conditions
if( nFrame == 11 && nRoll == 2 && frames[i-2] != 10 ) break;
if( nFrame == 12 && frames[i-1] != 10 && frames[i-2] != 10 ) break;
if( nFrame == 12 && nRoll == 2 ) break;
if( nFrame > 12 ) break;

}

if(!pula) { sb.append(score); pula = true; }
else { sb.append("\n" + score); }

}

System.out.println(sb.toString());

}

String newLine = System.getProperty("line.separator");
StringBuffer buffer = new StringBuffer();
int car = -1;
try {
while ((car > 0) && (car != newLine.charAt(0))) {
buffer.append((char)car);
}
if (car == newLine.charAt(0))
System.in.skip(newLine.length() - 1);
} catch (java.io.IOException e) { return (null);}
if ((car < 0) && (buffer.length() == 0)) return (null);
return (buffer.toString()).trim();
}

}
``````
thx
Eu sou foda? N

[_TANG_]
New poster
Posts: 15
Joined: Wed May 04, 2005 12:28 am
Location: Mexico

### No critical I/O

leonardooo, there's no critical I/O for this problem it's only a simulation problem just remember

after strike -> score += (10 + next 2 rolls)

after spare -> score += (10 + next roll)

no spare && no strike -> score += (roll1 + roll2)

always be 2 rolls ahead the frame you're calculating ... ... there is no trap in this problem

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
here is one input that I missed:
INPUT
X X X X X X X X X X X X
OUTPUT
300

leonardooo
New poster
Posts: 8
Joined: Sun Nov 28, 2004 9:26 am
Location: Campina Grande - PB / Brazil
One strike in the last roll (roll 10) duplicates points in the bonus roll (roll 11 and 12)? Or the points of the bonus roll are calculated separate?

One strike or spare in the bonus roll (11) duplicates points in the bonus roll (12)?

thx
Eu sou foda? N

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA
In roll 11 and 12, the points are not duplicated, that is they are counted only once.

Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

### Sample I/O

Here is some sample I/O for this problem.

Note that the maximal count of throws in a game is 21.
That happens for example when :
A) One makes let's say 10 Spares and
finally one more additional throw... OR ...
B) One makes 9 Spares ( or even not Spares but
even 9 Normal Double Throws ) plus a
Strike in the last throw plus Two more
additional throws ( due to the strike in the last throw ).

The number of frames in a game though is exactly 10
these are not counted as a frame ).

INPUT

Code: Select all

``````1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
X X X X X X X X X X X X
1 / 3 / 5 / X X X 3 / 5 / 1 2  8 / 2
X 1 / X 1 / X 1 / X 1 / X 1 / X
1 / X 1 / X 1 / X 1 / X 1 / X 9 / 0
1 / X 1 / X 1 / X 1 / X 1 / X 2 / 0
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X X X
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X 4 /
Game Over
``````

OUTPUT

Code: Select all

``````108
121
120
300
162
200
200
200
183
173``````
Good luck to everyone !

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai
i got TLE,very strange...
i cant find the error.....
who can help me....

Code: Select all

``````//584 Bowling
#include <iostream>
using namespace std;

int main()
{
long frame[10];
long score;
char str[100];
long f;
bool nextFrame;
while(cin.getline(str,100))
{
if(str[0]=='G')
break;
long i,j;
for(i=0;i<10;i++)
frame[i]=0;
nextFrame=false;
for(i=f=0;str[i]!='\0';i++)
{
switch(str[i])
{
case 'X':
frame[f]=10;
if(str[i+2]=='X')
{
frame[f]+=10;
if(str[i+4]=='X')
frame[f]+=10;
else
frame[f]+=str[i+4]-'0';
}
else
{
if(str[i+4]=='/')
frame[f]+=10;
else
frame[f]+=str[i+2]-'0'+str[i+4]-'0';
}
f++;
break;
case '/':
break;
case ' ':
break;
default:
frame[f]+=str[i]-'0';
if(str[i+2]=='/')
{
frame[f]=10;
if(str[i+4]=='X')
frame[f]+=10;
else
frame[f]+=str[i+4]-'0';
}
else
{
frame[f]+=str[i+2]-'0';
}
i+=2;
f++;
}
}
for(i=score=0;i<10;i++)
score+=frame[i];
cout<<score<<endl;
}
}

``````

Robert Gerbicz
Experienced poster
Posts: 196
Joined: Wed May 02, 2007 10:12 pm
Location: Hungary, Pest county, Halasztelek
Contact:

### Re: Sample I/O

Sedefcho wrote: INPUT

Code: Select all

``````1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
X X X X X X X X X X X X
1 / 3 / 5 / X X X 3 / 5 / 1 2  8 / 2
X 1 / X 1 / X 1 / X 1 / X 1 / X
1 / X 1 / X 1 / X 1 / X 1 / X 9 / 0
1 / X 1 / X 1 / X 1 / X 1 / X 2 / 0
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X X X
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X 4 /
Game Over
``````

OUTPUT

Code: Select all

``````108
121
120
300
162
200
200
200
183
173``````
My AC code gives 163 for the last but one test case (instead of 183).

hierony
New poster
Posts: 1
Joined: Thu Dec 19, 2013 1:59 am

### Re: 584 - Bowling - Need test input please

I'he tested so many Testcase.
but why still WA.

Can someone give me a tricky one Testcase?

praveenkumar13cs32
New poster
Posts: 4
Joined: Sat Dec 27, 2014 9:06 am

### WA: 584 - Bowling

plz help me
i had tried all input from UVA OJ discussion board and get correct anwer
but in uva online judge i got wrong answer why ?
plz help me

Code: Select all

``````#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int sa[256];
for(int i=48;i<=57;i++)
{
sa[i]=i-48;
}
sa[int('X')]=10;
char ch[1000];
while(gets(ch))
{
if(ch[0]=='G')
break;
for(int i=0,j=0;ch[i]!='\0';i++)
if(ch[i]!=' ')
ch[j++]=ch[i];
int score=0;
int frame=1;
int roll=0;
for(int i=0; ;i++)
{
if(ch[i]!='X' && ch[i]!='/')
{
if(ch[i+1]=='/')
{
score=score+10+sa[int(ch[i+2])];
}
else
score=score+sa[int(ch[i])];
roll++;
}
else if(ch[i]=='X')
{
score=score+sa[int(ch[i])];
if(ch[i+2]=='/')
score+=10;
else
{
score=score+sa[int(ch[i+1])]+sa[int(ch[i+2])];
}
roll=2;
}
else
roll++;
if(frame==10 && roll==2)
break;
if(roll==2)
{
frame++;
roll=0;
}
}
if(score>300)
cout<<300<<endl;
else
cout<<score<<endl;

}
return 0;
}
``````
inputs
• X X X X X X X X X X X X
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
X X X X X X X X X X X X
1 / 3 / 5 / X X X 3 / 5 / 1 2 8 / 2
X 1 / X 1 / X 1 / X 1 / X 1 / X
1 / X 1 / X 1 / X 1 / X 1 / X 9 / 0
1 / X 1 / X 1 / X 1 / X 1 / X 2 / 0
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X X X
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X 4 /
1 0 1 / 2 2 X 3 3 X 1 / 3 / X 1 2
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / X 8 0
1 0 1 / 2 2 X 3 3 X 1 / 3 / 1 / 8 / 9
X X X X X X X X X X X X
1 / 3 / 5 / X X X 3 / 5 / 1 2 8 / 2
X 1 / X 1 / X 1 / X 1 / X 1 / X
1 / X 1 / X 1 / X 1 / X 1 / X 9 / 0
1 / X 1 / X 1 / X 1 / X 1 / X 2 / 0
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X X X
3 / 4 4 8 / 9 2 7 / X X 2 / 9 / X 4 /
Game Over

my correct outputs
• 300
108
121
120
300
162
200
200
200
183
173
108
121
120
300
162
200
200
200
183
173