|In tennis, the two players play games, alternating which player is the server
in each game. When a player has won at least 4 points and has won at least 2 more points
than his opponent, he has won the game.
When a player has won at least 6 games and has won at least 2 more games than
his opponent, he has won the set.
We have a String points that tells us the result
of each point in a recent tennis match. Each character is either 'S' indicating
that the server won that point, or an 'R' indicating that the returner (the non-server)
won that point. There is no significance to the breaks between individual Strings
in points. All together they represent one sequence of points played in the match.
Call the player who serves in the first game Player A and his opponent Player B. We want to know the score in the first set, with the number of
games won by Player A, then a hyphen ('-'),
then the number of
games won by Player B. The data in
points may go beyond the end of the first set, in which case the extra data can
be ignored. The first set may not yet be completed,
in which case we want the score to include only the completed games.
Create a class TennisSet that contains a method firstSet that is given
String points and returns the score of the first set as a String. The
returned String must not contain any extra characters (such as spaces or leading zeros).