P1166 Bowling
Description
Bowling uses a rolling ball to knock down ten standing pins. A game has ten frames. In each frame, you may roll the ball once or more times, and scoring is based on the number of pins knocked down. The total score for a game is the sum of the scores of the ten frames. A frame’s score depends not only on that frame’s rolls, but may also depend on the rolls in the next one or two frames. That is, the number of pins knocked down by a roll in a later frame may be counted toward the score of one or two previous frames. The specific pin-knocking and scoring rules are as follows:
1. If the first roll of a frame knocks down all ten pins, then there are no more rolls in that frame (if it is the 10th frame, add two more rolls; we may call them the 11th and 12th frames, though not all situations require rolling the 11th and 12th balls). The score of that frame is $10$ plus the total pins knocked down by the next two rolls.
2. If the first roll of a frame does not knock down all ten pins, you may roll once more for the remaining pins. If the two rolls together knock down all ten pins, then there are no more rolls in that frame (if it is the 10th frame, add one more roll). The score of that frame is $10$ plus the pins knocked down by the next roll.
3. If the two rolls in a frame do not knock down all ten pins, then the frame ends. The score of that frame is the sum of pins knocked down in those two rolls.
In short, if a frame’s one or two rolls knock down all ten pins, then the frame’s score is the sum of the pins knocked down in the first three consecutive rolls starting from that frame’s first roll (one or two of those rolls may belong to the following frames). If the two rolls in a frame knock down fewer than ten pins, the frame’s score is simply the sum of those two rolls. Here is an example (the character `/` means knocking down all currently standing pins):
| Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: | :-----------: |
| Rolls | / | / | / | 72 | 9/ | 81 | 8/ | / | 9/ | / | 8/ | |
| Score per frame | 30 | 27 | 19 | 9 | 18 | 9 | 20 | 20 | 20 | 20 | | |
| Cumulative total | 30 | 57 | 76 | 85 | 103 | 112 | 132 | 152 | 172 | 192 | | |
Now, please write a real-time bowling scoring program to compute and display the scores after a frame ends. If a frame’s score cannot be determined yet, do not display that frame’s score (do not output it).
Input Format
A single line describing the rolls of the first several frames. Each frame is written with one or two characters, and each character represents one roll. The character `/` means knocking down all currently standing pins; otherwise, a digit character represents the number of pins knocked down in that roll. Frames are separated by a single space character.
For example, the input corresponding to the sample above is: `/ / / 72 9/ 81 8/ / 9/ / 8/`.
Output Format
Two lines. The first line lists the score for each frame; the second line lists the cumulative total up to the current frame. Separate scores with a single space.
Explanation/Hint
Translated by ChatGPT 5