Since the rules of basketball do not allow games to result in ties, comparing two teams during a tournament is usually done by comparing the number of games they've won.
When comparing two teams that have played a different number of games, the team that played k games less than the other gets k/2 added to its win total.
For further clarification, please see the following table (the notation 7/15 means that a team played 15 games and won 7 of them):
Team A Team B Difference
7 / 15 8 / 20 Team A played 5 games less than team B, so we assume it will win 2.5 games more.
Therefore Team A is (7 + 2.5) - 8 = 1.5 games ahead of team B.
8 / 8 18 / 18 Though both teams have won all their games, team A played 10 games less.
We assume it wins 5 of those 10 games, so it is 5 games behind team B.
20 / 40 10 / 20 Team B played 20 games less, so we assume it will have 10 more wins.
Therefore, the gap between the teams is 0.
Since this comparison is transitive (if team A is better than team B, and team B is better than team C, then team A is better than team C), the teams can be placed into the standings table according to this order. If the gap between two teams is 0, the team whose name comes earlier alphabetically is given the better rank.
You will be given a String[] teams, with the i-th element of teams representing the i-th team. Each element of teams will be formatted as "NAME WINS LOSSES" (quotes for clarity), where NAME is a sequence of uppercase letters representing the name of the team, and WINS and LOSSES are integers representing the number of games the team won and lost respectively. You are to sort teams from the best to worst according to the comparison method defined above, and return the standings as a String[]. Each element of the result must be formatted as "NAME GAP" (quotes for clarity), where NAME is the team's name and GAP is the gap between this team and the top team in the standings.
GAP must consist of one or more digits, followed by a decimal point, followed by exactly one digit. There must be no extra leading zeroes. For example, "0.0", "0.5" and "1.0" are valid, but ".5", "0", "05.0" and "5." are not.
|