Woburn Challenge 1998
Episode 2: The Hutts Strike back (Will Han be Spared?)
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 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:
- 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)
- 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, ie. all 10 pins are put back up.
- 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.
- 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.
- 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.
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 the total score of each player as shown in the example below:
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):
4 - 20 - 20 - 10 - 6 - 24 - 20 - 15 - 9 - 5 => total = 133
Sample for player
2 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 - 30 => total = 300 (maximum score)
Point Value: 10
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3