Tennis
Time limit1sMemory limit128 MB
Read a sequence of tennis points (A/B), split it into completed games using the 15-30-40-deuce rules, and output the final game count.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation
- Solved
- No attempts yet
Problem
Tennis has an unusual scoring system: 15, 30, 40, game. On top of that there is the deuce: at 40-40 a player must get 2 points ahead of the opponent to win the game.
In this problem you are given who won each point and must work out the score of a tennis match. For simplicity the two players are called A and B. The points are given as a sequence of letters, where A means a point won by player A and B a point won by player B. Here is an example:
ABAABBAABABAABABBB
Remember, to win a game a player must score 4 points and also be at least 2 points ahead. In the example above, the first game is ABAABBAA, won by player A: it went to deuce and then player A won two points in a row. The second game is BABAABABBB, won by player B: it also went to deuce, player A went ahead by 1 but player B caught up and then won the last 2 points. After all of that the score is 1 game all.
Input
The input consists of several strings, each on its own line. No line contains more than 250 characters. The last line contains only the # character and must not be processed.
Each line represents part of a tennis match, that is, a number of completed games, and contains only the uppercase letters A and B representing the points won by each player. Treat each line independently and work out the score, in games, after the points shown.
Output
For each input line, print one line in the form A x B y, where x is the number of games won by A and y is the number of games won by B.