Problem Statement
In this problem, you are given the log of successful throws during a basketball game. Your task will be to calculate the final score of the game. The throws are given in int[]s time, basket and points. The i-th throw is represented by the following parameters:
Let SA and SB be the final scores of teams A and B, respectively. Return a String of the form "SA:SB". Both SA and SB must be written without unnecessary leading zeros.
- time[i] -- the time when the throw was made (in seconds since the beginning of the game).
- basket[i] -- the ID of basket (1 or 2) into which the throw was made.
- points[i] -- the number of points (1, 2 or 3) that this throw contributed to the score.
Let SA and SB be the final scores of teams A and B, respectively. Return a String of the form "SA:SB". Both SA and SB must be written without unnecessary leading zeros.
Definition
- Class:
- BasketballGame
- Method:
- getScore
- Parameters:
- int[], int[], int[]
- Returns:
- String
- Method signature:
- String getScore(int[] time, int[] basket, int[] points)
- (be sure your method is public)
Constraints
- time, basket and points will each contain between 1 and 50 elements, inclusive.
- time, basket and points will contain the same number of elements.
- Each element of time will be between 1 and 2880, inclusive.
- Elements of time will be sorted in non-decreasing order.
- Each element of basket will be between 1 and 2, inclusive.
- Each element of points will be between 1 and 3, inclusive.
Examples
{500, 1000, 1500, 2000}{1, 2, 1, 2}{1, 2, 3, 1}Returns: "2:5"
At second 500, we have a successful throw into basket 1 for 1 point. The score is 1:0. At second 1000, we have a successful throw into basket 2 for 2 points. The score is 1:2. At second 1500, we have a successful throw into basket 1 for 3 points. As this throw is already in the second half of the game, the score is now 1:5. At second 2000, we have a successful throw into basket 2 for 1 point. The final score is 2:5.{1440, 1440, 1441, 1441, 1441}{1, 1, 1, 1, 1}{3, 3, 2, 1, 1}Returns: "6:4"
In this game all successful throws were made into the same basket.{2000, 2100, 2120, 2121, 2121, 2880}{2, 1, 1, 1, 2, 2}{3, 1, 2, 3, 1, 2}Returns: "6:6"
All succesful throws were made in the second half of the game and the final result is a draw.{1, 2, 3, 1000, 2000}{1, 1, 1, 1, 2}{3, 2, 1, 2, 3}Returns: "11:0"
Bad luck for team B.{274,442,548,1116,1554,2041,2060,2404,2654}{1,2,1,2,2,2,1,2,2}{2,2,1,1,3,1,3,1,2}Returns: "10:6"