시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 256 MB | 32 | 20 | 16 | 64.000% |
In this problem you will have to decide the final score of a game of bowling. A game of bowling has 10 frames. The tenth frame works in a slightly different way than the first 9.
For the first 9 frames, each will consist of 1 or 2 rolls. You will be presented with 10 pins. If you hit all 10 pins in the first roll you make a “strike”, and the frame is over. Otherwise you have a second roll to hit the remaining pins. If you hit all remaining pins you score a “spare”; otherwise you have an “open frame”. The number of points an open frame gives is simply the total number of pins you hit. A spare gives 10 points plus the number of pins hit on your next roll (in the next frame). A strike gives 10 points plus the number of pins hit on the next two rolls (in the next frame, or possibly the next two frames if you hit a strike in the next roll).
The last frame consists of 2 or 3 rolls. The way it works can be explained as:
Note that the number of points in the last frame is the total number of pins hit in all rolls.
Your job is to compute the total score for a game of bowling given the scores for each of ten frames. A strike is represented by an “X”, a spare is represented by the number of pins hit in the first roll followed by a slash (“/”) and an open frame is represented by 2 numbers: the number of pins hit in each roll. Similarly, the tenth frame is represented either as: (1) “X X X”, or (2) “X X a”, or (3) “X a /” or (4) “X a b” or (5) “a / X” or (6) “a / b” or (7) “a b”, where a and b are numbers.
Your program must read the notated scores for each of a set of games (preceded by the number of games) and compute the total scores. Note that the frames are not delimited in any way---it’s your job to figure out if a frame has one, two, or three rolls.
Print the total scores.
3 2 6 5 0 4 4 0 9 3 4 8 1 1 4 3 2 5 4 6 1 3 / 4 4 X 5 3 9 0 1 / X 8 / 7 2 X 4 3 8 1 X X 3 / 4 5 1 / X X 3 / 4 / 8
72 140 170
For the third input the game went like this:
Frame | Notation | Points | Total |
---|---|---|---|
1 | 8 1 |
8 + 1 = 9 | 9 |
2 | X |
10 + 10 + 3 = 23 | 32 |
3 | X |
10 + 3 + 7 = 20 | 52 |
4 | 3 / |
10 + 4 = 14 | 66 |
5 | 4 5 |
4 + 5 = 9 | 75 |
6 | 1 / |
10 + 10 = 20 | 95 |
7 | X |
10 + 10 + 3 = 23 | 118 |
8 | X |
10 + 3 + 7 = 20 | 138 |
9 | 3 / |
10 + 4 = 14 | 152 |
10 | 4 / 8 |
4 + 6 + 8 = 18 | 170 |