ZOJ Problem Set - 1215
Technology hasn't come quickly to Joe's Bowl-a-rama. Minimum wage teens, and
not those fancy machines, still reset the pins, and the grizzled veteran bowlers
still mark up their own score sheets. Unfortunately for Joe Junior, who now
runs the Bowl-a-rama, people his age are a little shaky on the scoring, especially
after the second beer, and are staying away in droves, bowling instead at the
new CyberBowl 2000 down the street, which scores automatically. Joe Junior figures
that if he puts a cheap PC next to every lane, he can get a cheap, semi-automatic
scoring system going. His plan is for the PC's to run software that only requires
a bowler to enter the number of pins that remain standing after every throw
-- and the software will keep score and tell the bowler when his game is over.
Joe Junior would like to hire you to write the software.
Now, are you ready to sign on to write the software?
Input contains several complete or partial games. A game is described by a
single line with a single name, not to exceed 12 characters, and sequence of
numbers, one for each ball thrown indicating the number of pins still standing
after that throw. According to the rules, there are from 11 to 21 throws in
a game; no input line will show throws beyond the last throw of the game. The
number of games described in the input is not predetermined, so you'll have
to detect the end of the input.
The standard output will contain, on successful completion of the program, two output lines for each input line. The first output line contains the name of the bowler and a record of the throws in each frame. This record shows, for each frame, the number of pins knocked down for each throw as a digit, with some exceptions. For a throw that knocks down no pins, a dash ('\') is used instead of a `0'. An 'X' indicates a throw that knocks down all 10 pins on the first try. A slash ('/') indicates a throw that finishes knocking down all the pins, after the previous throw left some standing. Otherwise, a throw is shown as a digit (`1' to `9'). The number of throws in a frame may be one (a strike in frames 1 to 9), or three (a strike or spare in frame 10, followed by bonus balls), but is usually two. Here are examples of throw markings for a variety of situations:
The second output line shows cumulative scores. The cumulative score for the first frame is just the score for pins knocked down in frame, plus bonus points if they apply. The cumulative score for any other frame is the cumulative score for the previous frame plus the score for pins knocked down in that frame, plus the bonus pins that may have been earned for a strike or spare in this frame. It is possible to have markings on line one for a frame, but no score on line two, in the event that the frame is a strike or spare but the bonus points for the frame aren't yet known.
The format for this output requires that the bowler's name be left-justified. The fields for each frame are three characters wide, with a space separating each field. The fields begin in columns 14, 18, 22, and so on. The record of the throws in the first line is left justified in its field. The cumulative score is right justified in its field. There is a blank line that separates the scores of one bowler from the scores of another.
Chuck 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
The line of digits is intended to guide you in proper output alignment, and is not part of the output that your solution should produce.
Solly X X
X X X X X X
Lothar -/ -/ -/
Brutus 54 8/ 4/ 1
McGillicuddy X X 9/
Homer X -/ X
Barney X X
X X X X X X
Source: South Central USA 1998