#C13152. Average Score Ranking
Average Score Ranking
Average Score Ranking
You are given a series of student records with their scores. For each student, you need to calculate the average score, ignoring any non-numeric score values. If a student does not have any valid scores, their average is considered to be 0. Afterwards, sort the students in descending order by their average score. In case of ties, sort the students alphabetically by name.
Formally, if a student has valid scores (s_1,s_2,\dots,s_n) then compute the average as (\bar{s} = \frac{\sum_{i=1}^{n} s_i}{n}) if (n > 0) and 0 otherwise. The sorted output should be based on (-\bar{s}) and, in the event of a tie, the student names in ascending order.
Input is read from standard input and output is written to standard output.
inputFormat
Standard input consists of multiple lines. The first line contains an integer (N) representing the number of students. Each of the following (N) lines contains a student's record in the following format:
name K token1 token2 ... tokenK
where
• name is a string (without spaces) representing the student’s name, • K is an integer indicating the number of tokens that follow, • Each token may be a valid number (integer or float) or a non-numeric value. Non-numeric tokens should be ignored in the calculation of the average.
outputFormat
For each student, print one line containing the student's name and their average score (formatted to two decimal places), separated by a space. The records must be sorted in descending order of average score, with ties broken by alphabetical order of the student names.## sample
5
Alice 3 88 76 92
Bob 3 82 89 85
Charlie 3 91 88 85
David 3 72 85 89
Eva 3 65 95 70
Charlie 88.00
Alice 85.33
Bob 85.33
David 82.00
Eva 76.67
</p>