Problem Statement
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).
Definition
- Class:
- TennisSet
- Method:
- firstSet
- Parameters:
- String[]
- Returns:
- String
- Method signature:
- String firstSet(String[] points)
- (be sure your method is public)
Notes
- We are NOT using the tiebreaker which is sometimes used when a set reaches 6-6.
Constraints
- points will contain between 1 and 50 elements inclusive.
- Each element of points will contain between 1 and 50 characters inclusive.
- Each element of points will contain only 'S' and 'R'.
Examples
{"SSSSSSSSSSSSSSS"}Returns: "2-1"
The first game was won by Player A in four points. Then B served the second game and won it in four points. Then A served again and won 4 points in a row. The fourth game is still in progress (with B ahead by 3 points).{"SS","SRSS","RRRRR"}Returns: "2-0"
Player A won the first game 4 to 1. As receiver in the second game, A also won 4 points to 1 point. Only one point has been played in the third set so far.{"SSSSRRRRSSSSRR","RRSSSSRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR","R"}Returns: "6-0"
Player A won all the games without losing a single point. There is a lot of extra data that applies to other sets and is ignored.