#P1166. Real-time Bowling Score Calculator
Real-time Bowling Score Calculator
Real-time Bowling Score Calculator
This problem requires you to simulate a real-time bowling score calculator. In bowling, a game consists of ten frames and the scoring rules are as follows:
- If a frame's first roll knocks down all 10 pins (a strike), then no second roll is taken for that frame (except in the 10th frame). The frame score is computed as
score = 10 + ri+1 + ri+2 where ri+1 and ri+2 are the scores on the next two rolls. - If the first roll is not a strike, a second roll is taken and if the total pins from the two rolls equal 10 (a spare), then the frame score becomes
score = 10 + ri+2 where ri+2 is the score on the next roll. - If neither a strike nor a spare is achieved, the frame score is simply the sum of the two rolls.
For the 10th frame, if a strike is scored on the first roll, two additional rolls are granted; if a spare is made (using two rolls), one additional roll is granted, to allow bonus computation.
The twist is that the input may represent a partial game. After each completed frame, if the bonus rolls required for computing a strike or spare are not yet available, then the score for that frame should not be displayed.
Given a sequence of rolls (each an integer representing knocked down pins), compute and display the cumulative scores for each finalized frame (i.e. those frames for which the score can be completely determined). The formulas used are in LaTeX format, for example: $10+ r_{i+1} + r_{i+2}$ for a strike and $10+ r_{i+2}$ for a spare.
inputFormat
The input consists of a single line containing space-separated integers. Each integer denotes the number of pins knocked down in a roll. The list might represent a partial game, so some frames might be incomplete.
outputFormat
Output a single line with the cumulative scores for each finalized frame, separated by a space. Do not output a frame's score if its bonus rolls have not been recorded yet.
sample
10 10 10 7
30 57