Ranking Rows by One Column
Riverbend Supply publishes a supplier league table each quarter. The raw file holds one supplier per line — an id and that supplier's score — and it arrives in id order. The published table runs from the best score down to the worst. Suppliers who tie on score are printed in the reverse of the order they appear in the raw file, so the later line comes first; that is what the publishing system has always done and what the archived tables are checked against.
Task: Print the league table, best score first, with each supplier's id kept beside its score.
Input
The first line holds a single integer n, the number of suppliers. Each of the next n lines holds an id and a score separated by a single space. Both are whole numbers.
Output
n lines, each holding an id and a score separated by a single space, ordered from the highest score to the lowest. Suppliers sharing a score appear in the reverse of their input order.
Example:
Input:
3
101 70
102 90
103 80
Output:
102 90
103 80
101 70
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in