#K51112. Class Average and Student Ranking
Class Average and Student Ranking
Class Average and Student Ranking
You are given a list of students with their names and grades. Your task is to calculate the class average grade rounded to 2 decimal places and to produce a ranking list of the students based on their grades.
The ranking is determined by the following rules:
- Students are ordered in descending order of grade.
- If multiple students have the same grade, they are ordered alphabetically by name.
- Students with the same grade share the same rank. The rank for a student is equal to 1 + (number of students with a strictly higher grade).
If there are no students (i.e. n = 0), the average should be 0.00 and no ranking should be printed.
Note: All formulas are calculated using the formula
\( \text{average} = \frac{\sum_{i=1}^{n} \text{grade}_i}{n} \)
inputFormat
The input will be read from stdin and has the following format:
n name1 grade1 name2 grade2 ... nameN gradeN
Where n
is a non-negative integer representing the number of students. Each of the following n
lines contains a student's name (a string without spaces) and an integer grade separated by a space.
outputFormat
The output should be printed to stdout and must include:
- The first line is the class average grade rounded to 2 decimal places.
- Each of the following lines represents a student in the ranking list in the format
rank. name
.
3
John 75
Alice 85
Bob 90
83.33
- Bob
- Alice
- John
</code></pre>