#K11776. Leaderboard Ranking
Leaderboard Ranking
Leaderboard Ranking
You are given a list of players with their scores. Your task is to compute the leaderboard ranking by sorting the players in descending order of their scores. Players having the same score will receive the same rank, and the subsequent rank number will be skipped accordingly. For example, if two players share the top score, both are assigned rank 1, and the next player gets rank 3.
The ranking process can be formulated as follows:
$$\text{rank}[i] = \begin{cases} 1, & \text{if } i = 0 \ \text{rank}[i-1], & \text{if } score[i] = score[i-1] \ i+1, & \text{otherwise} \end{cases} $$Note: When players have the same score, they should retain their order from the input.
Input is provided via standard input and output via standard output.
inputFormat
The first line contains an integer n representing the number of players. The following n lines each contain a player's name (a string without spaces) and an integer score, separated by a space.
For example:
5 Alice 50 Bob 75 Charlie 75 David 55 Eve 20
outputFormat
Output n lines, each containing the player's name and their computed rank, separated by a space, sorted in descending order of their scores (and in the original order if the scores are the same).
For the example above, the output should be:
Bob 1 Charlie 1 David 3 Alice 4 Eve 5## sample
1
Alice 50
Alice 1
</p>