A Duckpin Tournament

In a Duckpin Tournament, the winner is decided by the player with the highest number of tournament points earned by playing a number of matches. Points are awarded for winning a match and scoring the highest game during the match. A duckpin match consists of a series of three lines, or games. The match winner is the player with the highest series score, i.e., three game total. The high game winner is the player with the highest score for a single line during the match. A line of duckpins is divided into ten frames. In each frame a player has three tries to knock down ten duckpins with a ball. If the player knocks down all ten pins on the first try, a strike is awarded and the frame is concluded (see exception below). If the player knocks down all ten pins in two tries, a spare is awarded and the frame is concluded (see exception below). If during any of the three tries a foul is committed by the player crossing the foul line, the frame is concluded and only the pins knocked down prior to that try are counted for the frame. The points earned in a frame equal the number of pins knocked down plus any bonus points earned for a spare or a strike. The bonus points earned for a spare or strike equal the number of pins knocked down on the next try following a spare or on the next two tries following a strike. A foul following a spare or strike earns zero bonus points unless the foul occurs on the second try following a strike; then only the bonus points earned on the first try are counted. A spare or a strike normally concludes the frame. However, if a spare or a strike occurs in the tenth frame, the frame is concluded by the player immediately taking the appropriate number of tries to earn the bonus points. The score for each frame equals the number of points awarded for the frame plus the score in the previous frame. Write a program to produce a scoring summary for one or more duckpin matches of one to four players. Input The input for each match consists of an integer indicating the number of players, a list of players’ names (each name is a max. length of 10 alpha characters), followed by lines of integers representing the number of pins knocked down by each player on the first, second, or third try in each game in the match. The match is concluded by ‘#’. The input is concluded when the number of players for a match is zero. Since each match consists of three games and each player gets three tries per frame in each game, the total number of lines of integers in the match will be nine times the number of players. The players play in the order that the names were listed. The order of the lines is:

  1. three lines for the first player in the first game followed by three lines for each of the other players for the first game,
  2. three lines for the first player in the second game followed by three lines for each of the other players for the second game,
  3. similarly for the third game with the match concluded by ‘#’. The line of integers representing the first try will have at least ten integers but no more than twelve. Since a second or third try may not be attempted in a frame, the second and third lines may have less than ten integers. A negative integer indicates the number of pins knocked down however the player fouled on the try.

2/3 Output The output shows a frame by frame score for each player for each game in the match. Each line of output consists of the player’s name, left justified in a field ten characters wide, and ten integers, right justified with a field four characters wide. At the end of the match report the match and high game winner followed by a blank line. No two players will get the same high score. Note: The explanations, that appear in parentheses, on the right of the sample input are not part of the real input file. Sample Input 3 Tim Jim Bob 578510101089 5214 10 011 11 101098991099 101010 (scores for Tim's first game) (scores for Jim's first game) (scores for Bob's first game) (scores for the second game) (blank line shows no 3rd tries were used in this game) (scores for the third game) 98 1110 111 11 7689-1089810 3221 111 211 1081 0888976-679 6121013 30 30 1110 0 571098910 7897 53 121 -32 1 9 8 9 8 9 7 10 9 9 9 111212 010 1111 567891010-1010 42311 021 8 7 6 10 9 9 10 7 8 6 223 10 313 10111 9 8 9 9 9 8 10 10 10 8 121112 1 10 10 10

0

Sample Output Tim 172636 Jim 294967 Bob 162645 Tim 91836 Jim 173757 Bob 182846 46 76 104 123 133 143 173 77 96 106 126 145 164 182 55 55 65 83 93121140 465665747493102 75 94 114 131 138 157 174 658292111121140150 1

3/3 Tim Jim Bob Jim has the high series score of 499. Bob has the high game score of 200. 9 19 37 47 67 87 97 97127157 17 27 36 56 75 85105123133143 18 37 56 75 93113143171190200