#K36837. Calculate Average Grades

    ID: 25843 Type: Default 1000ms 256MiB

Calculate Average Grades

Calculate Average Grades

You are given records of students along with their grades in multiple subjects. Your task is to calculate the average grade for each student and then output the list of students sorted in descending order by their average grade. In case two students have the same average grade, sort them in alphabetical order by their names.

Mathematically, if a student has grades g₁, g₂, ..., gₘ, then the average grade (\bar{g}) is computed as [ \bar{g} = \frac{g_1 + g_2 + \cdots + g_m}{m} ] Round the average to two decimal places.

Input will be provided via standard input (stdin) and output must be written to standard output (stdout).

inputFormat

The input begins with an integer (n) representing the number of students. For each student, the input contains:

  • A line with the student's name (a string without spaces).
  • A line with an integer (m), the number of subjects.
  • (m) subsequent lines, each containing a subject name (string) followed by an integer grade.

All input is read from stdin.

outputFormat

For each student, print a line containing the student's name followed by the average grade (rounded to two decimal places). The students must be listed in descending order of their average grade. If two or more students have the same average grade, they should be sorted alphabetically by name. Output is printed to stdout.## sample

4
Alice
3
Math 90
Science 80
English 70
Bob
3
Math 100
Science 90
English 80
Charlie
3
Math 70
Science 60
English 50
David
3
Math 90
Science 80
English 70
Bob 90.00

Alice 80.00 David 80.00 Charlie 60.00

</p>