Problem Description
Rar the Cat and Potato are playing a table tennis match! After playing a long and arduous match, they can't decide who has won! OH NO! You, being the ultimate master, must now decide for them who has won.
A table tennis match is played in a series of games. To win a game, the following conditions must be met:
- The winner must get at least 11 points.
- The winner must win by at least 2 points.
At the end of each game, the score is then tabulated. The player that first wins 3 games will win the match.
You will be given a string containing a record of the winner of each point. For example, "RPPRPPPRRPPPPPRP" means that Rar the Cat has won the first point, Potato wins the next two points, Rar wins the next point, etc, etc. In this case, Potato wins the game.
Also, when one game ends, the next point would be from the next game. The input log will also be guranteed to be valid.
Your program must implement the following functions:
- string winner(string S), which returns "Rar" or "Potato" based on the match.
Input
Your function will be given a log of the match based on the description above.
Output
Your function must either return "Potato" or "Rar", depending on the victor of the match.
Limits
The length of the log will be at most 1000.
Sample Input 1
RPPRRPPRPRRPRPRPRPRRRPPRPPPRRPPPPPRPPPPRPRPRPPPRPPRPRPPRPPPRRPPPPPRRRP
Sample Output 1
Potato
Explaination for Sample 1
The first game is denoted by "RPPRRPPRPRRPRPRPRPRR". In this game, Rar the Cat wins by 11-9.
The second game is denoted by "RPPRPPPRRPPPPPRP". In this game, Potato wins by 5-11.
The third game is denoted by "PPPRPRPRPPPRPPRP". In this game, Potato again wins by 5-11.
The fourth game is denoted by "RPPRPPPRRPPPPPRRRP". In this game, Potato wins by 7-11.
Thus, overall, Potato wins Rar the Cat by 3 games to 1.