WC '98 P2 - The Hutts Strike Back

View as PDF

Submit solution

Points: 10
Time limit: 1.0s
Memory limit: 16M

Problem type
Woburn Challenge 1998

Han Solo is deep in debt to Pizza the Hutt and Atilla the Hutt, Jabba's lesser known but equally blobular cousins. Together, Jabba, Atilla and Pizza form a deadly trio known as The Other Three Tenors. Pizza, being the nice blob that he is, has made Han an offer he can't refuse to rectify the situation. He has challenged Han to a game of bowling - if Han loses, he will face the ultimate punishment of being put in a holding cell listening to recordings of C3PO's infernal whining for the rest of his life. Unfortunately, the Hutt family have been cursed with no elbows and thus can't bowl; so instead they have hired Peter "Three Thumbs" Plachta to bowl for him. Your job is to write a program that will tally up the scores so that they can determine who wins.

In case you're unfamiliar with the rules of bowling, here's how it works:

  1. There are 10 frames - in each frame, both bowlers, in turn, get 2 throws to try to knock down as many of the 10 pins as possible (the 10th frame is an exception - see below).
  2. If a bowler fails to knock down all the pins, he is assigned a score based on the number of pins he knocks down (between 0 and 9) in each throw. At the beginning of each bowler's turn, all the pins are reset, i.e. all 10 pins are put back up.
  3. If a bowler knocks down all the 10 pins on the first throw, he is awarded a Strike and that bowler does not get a 2nd throw in that frame (except in the 10th frame). If a bowler knocks down all 10 pins in two throws, he is awarded a Spare.
  4. If a bowler is awarded a Strike, he gets 10 points for that frame AND he also counts his scores from the next 2 throws towards his score on the current frame (of course, those throws also count for the frame in which they are actually bowled). If a bowler is awarded a Spare, he gets 10 points for that frame AND he also counts his score from the next throw towards his score on the current frame.
  5. If a bowler bowls a Strike in the 10th (final) frame, he gets 2 more throws to add to the Strike. If he bowls a Spare in the 10th frame, he gets 1 more throw to add to the Spare. Those throws don't count on their own - they only count towards the Strike or Spare. You get at most 3 throws in the 10th frame.

Input Specification

The first line of the input will be the number of bowlers.
Following this is the result of each throw by each bowler (X = Strike, / = Spare, 0..9 = knocked # of pins down).
There may be anywhere between 1 and 5 bowlers given - each bowler will be on a different line.

Note: There is no space between throws in a frame (so for the example below, in the 1st frame, on the first throw, 2 pins were knocked down and on the second throw, 2 more pins were knocked down).
Frames are separated using 1 hyphen.
If a strike was bowled in a frame, there is no 2nd throw in that frame and so there is a blank space in the data file after the X to signify that there was no 2nd throw.

Output Specification

Output the total score of each player as shown in the example below:

Sample Input

2
22-4/-X -55-42-X -X -4/-54-23
X -X -X -X -X -X -X -X -X -XXX

Sample calculation for player 1 (score for each frame is shown after considering subsequent throws if strike/spare):

\displaystyle 4 - 20 - 20 - 10 - 6 - 24 - 20 - 15 - 9 - 5 \implies \text{total} = 133

Sample for player 2:

\displaystyle 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 \implies \text{total} = 300\text{ (maximum score)}

Sample Output

133
300

Comments

There are no comments at the moment.