#C13510. Students Above Average Age and Their Average Grades
Students Above Average Age and Their Average Grades
Students Above Average Age and Their Average Grades
You are given a list of student records. Each student record contains the student's name, age, and a list of grades. Your task is to determine the average age of all students and then output, in the original order, the name and average grade (rounded to two decimal places) of each student whose age is strictly greater than the average age.
Let \( n \) be the total number of students, and let the ages be \( age_1, age_2, \dots, age_n \). The average age is given by:
[ \text{average_age} = \frac{\sum_{i=1}^{n} \text{age}_i}{n} ]
For every student whose age \( a \) satisfies \( a > \text{average\_age} \), compute their average grade as follows, where there are \( m \) grades \( g_1, g_2, \dots, g_m \):
[ \text{average_grade} = \frac{\sum_{j=1}^{m} g_j}{m} ]
Output each qualifying student's name along with their average grade formatted to two decimal places. If no student meets the criteria, output nothing.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains an integer \( n \), representing the number of students.
- For each student, there are 4 subsequent lines:
- A string representing the student's name.
- An integer representing the student's age.
- An integer \( m \) representing the number of grades.
- A line with \( m \) space-separated integers representing the student's grades.
For example:
4 John 20 3 70 80 90 Jane 22 3 85 91 78 Doe 21 3 84 77 92 Alice 23 3 95 80 85
outputFormat
For each student whose age is strictly greater than the average age, output a line on standard output (stdout) with the student's name followed by a space and their average grade (rounded to two decimals). If no student qualifies, output nothing.
For the sample input above, the expected output is:
Jane 84.67 Alice 86.67## sample
4
John
20
3
70 80 90
Jane
22
3
85 91 78
Doe
21
3
84 77 92
Alice
23
3
95 80 85
Jane 84.67
Alice 86.67
</p>