020-005-007
Game Leaderboard Management System
Hard
Problem Description
In this problem, you will create a program that reads player names and scores, manages them using a Player class implementing the Comparable interface, sorts by score in descending order, and displays the ranking to standard output.
Input Format
The first line contains the number of players n.
The next n lines each contain player name and score (space-separated).
Output Format
Display rankings in descending order of score (highest first).
Each line should be in the format "rank. player_name: score".
If scores are tied, maintain input order.
Constraints
- 1 ≤ n ≤ 100
- Scores are integers from 0 to 10000
- Player names are alphanumeric within 20 characters
Key Points
- Create a
Playerclass with name and score fields, implementingComparable<Player> - In
compareTo(), returnother.score - this.scoreto achieve descending order sorting - Pass your
List<Player>toCollections.sort()to sort using yourcompareTo()logic - Output each line using
System.out.printf("%d. %s: %d%n", rank, player.name, player.score)
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up