#C12983. Calculate Student Averages
Calculate Student Averages
Calculate Student Averages
In this problem, you are given a CSV-formatted input from standard input. The first line is a header row with column names (the first column is always the student's name, and the remaining columns represent grades in various subjects). Each subsequent line contains the name of the student followed by their grades. Some grade fields may be empty, which should be treated as missing (i.e. not counted in the average). Your task is to compute the average grade for each student. If a student does not have any grade, then their average is defined as 0. The result should be output as CSV text to standard output with exactly two columns: Name and Average Grade.
Formally, if a student has grades (g_1, g_2, \dots, g_k) (ignoring missing values), the average is (\frac{\sum_{i=1}^k g_i}{k}). Use one decimal precision for the average.
inputFormat
The input is provided on standard input and consists of multiple lines. The first line is a header (for example: Name,Subject1,Subject2,Subject3
). Each subsequent line represents a student's record: the first field is the student's name, and the following fields represent scores in different subjects. Fields are separated by commas, and an empty field indicates a missing grade.
outputFormat
Print to standard output a CSV text with a header line Name,Average Grade
and one line per student containing the student's name and their computed average grade (using one decimal place).## sample
Name,Subject1,Subject2,Subject3
Alice,90,85,
Bob,70,,80
Charlie,,,
Diane,88,78,92
Name,Average Grade
Alice,87.5
Bob,75.0
Charlie,0.0
Diane,86.0
</p>