Page 1 of 1

584 - Bowling

Posted: Sat Apr 23, 2005 4:28 pm
by Sirso
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!

me too

Posted: Sun Apr 24, 2005 7:15 am
by leonardooo
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;
    	
    	String input = readLn();
    	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); }
    		
    		input = readLn();
    	}
    	
    	System.out.println(sb.toString());

    }

    static String readLn() {
        String newLine = System.getProperty("line.separator");
        StringBuffer buffer = new StringBuffer();
        int car = -1;
        try {
            car = System.in.read();
            while ((car > 0) && (car != newLine.charAt(0))) {
                buffer.append((char)car);
                car = System.in.read();
            }
            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 :cry: :cry:

No critical I/O

Posted: Tue May 10, 2005 4:49 pm
by [_TANG_]
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 ... :wink: ... there is no trap in this problem

Posted: Fri May 13, 2005 1:56 pm
by shamim
here is one input that I missed:
INPUT
X X X X X X X X X X X X
OUTPUT
300

Posted: Sun May 22, 2005 10:32 am
by leonardooo
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

Posted: Mon May 23, 2005 11:41 am
by shamim
In roll 11 and 12, the points are not duplicated, that is they are counted only once.

Sample I/O

Posted: Thu Jul 14, 2005 3:25 pm
by Sedefcho
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
( if there's an additional throw or even two additional throws
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 !

Posted: Wed Aug 24, 2005 10:26 am
by sunnycare
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;
    }
}
                

Re: Sample I/O

Posted: Wed Feb 06, 2008 12:17 am
by Robert Gerbicz
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).

Re: 584 - Bowling - Need test input please

Posted: Thu Mar 13, 2014 1:00 am
by hierony
I'he tested so many Testcase.
but why still WA.

Can someone give me a tricky one Testcase?
thanks in advance.

WA: 584 - Bowling

Posted: Mon Apr 20, 2015 8:11 pm
by praveenkumar13cs32
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