Loading...
Loading...
A class teacher has the marks of n students in a mock test. For the notice board, she wants the list sorted from the highest marks to the lowest. When two students have the same marks, the student whose name comes first in alphabetical order is listed first.
Print the sorted list, one student per line.
Example
Input
5 ravi 78 anita 92 karan 78 meena 85 arjun 78
Output
anita 92 meena 85 arjun 78 karan 78 ravi 78
anita (92) and meena (85) come first. Three students have 78, so they are listed as arjun, karan, ravi.
Try the problem first. Open one hint at a time.
Keep each name and its marks together, for example in a small class or a record, so they move together while sorting.
Write one comparison rule: first compare the marks with the higher marks first; only when they are equal, compare the names.
For the names, String.compareTo already gives alphabetical order.
Build the output in a StringBuilder and print it once at the end.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor