584 - Bowling

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

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

584 - Bowling

Post by Sirso » Sat Apr 23, 2005 4:28 pm

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!

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

me too

Post by leonardooo » Sun Apr 24, 2005 7:15 am

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:
Eu sou foda? N

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

No critical I/O

Post by [_TANG_] » Tue May 10, 2005 4:49 pm

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

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Fri May 13, 2005 1:56 pm

here is one input that I missed:
INPUT
X X X X X X X X X X X X
OUTPUT
300

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

Post by leonardooo » Sun May 22, 2005 10:32 am

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

User avatar
shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

Post by shamim » Mon May 23, 2005 11:41 am

In roll 11 and 12, the points are not duplicated, that is they are counted only once.

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

Sample I/O

Post by Sedefcho » Thu Jul 14, 2005 3:25 pm

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 !

sunnycare
Learning poster
Posts: 74
Joined: Tue Mar 08, 2005 2:35 am
Location: China , Shanghai

Post by sunnycare » Wed Aug 24, 2005 10:26 am

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

Post by Robert Gerbicz » Wed Feb 06, 2008 12:17 am

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

Post by hierony » Thu Mar 13, 2014 1:00 am

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

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

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

WA: 584 - Bowling

Post by praveenkumar13cs32 » Mon Apr 20, 2015 8:11 pm

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

Post Reply

Return to “Volume 5 (500-599)”