#C13409. Average Student Grades
Average Student Grades
Average Student Grades
You are given data for a number of students. For each student, their name and a list of integer grades are provided. Your task is to calculate the average grade for each student. The average is computed as \(\frac{\text{sum of grades}}{\text{number of grades}}\) and must be rounded to two decimal places. If a student has no grades, then the average is defined to be null
.
The final output should be a JSON object (dictionary) mapping each student's name to their average grade (using a JSON number rounded to two decimal places) or null
if there are no grades. Read input from standard input (stdin
) and output the result to standard output (stdout
).
inputFormat
The input is given through stdin
in the following format:
- The first line contains an integer \(n\), which represents the number of students.
- For each student, there are multiple lines:
- A line containing the student's name (a string without spaces).
- A line containing an integer \(m\), representing the number of grades.
- If \(m > 0\), a line containing \(m\) space-separated integers representing the grades.
outputFormat
Output a single line to stdout
: a valid JSON object (dictionary) where each key is a student's name and the value is the average grade (rounded to two decimal places) or null
if the student has no grades.
3
Alice
3
85 90 78
Bob
2
70 80
Charlie
0
{"Alice":84.33,"Bob":75.00,"Charlie":null}