#C13897. Student Grades Manager
Student Grades Manager
Student Grades Manager
This problem requires you to manage a collection of students and their grades. You must implement a program that supports various operations:
- ADD name grade: Add a student with the specified grade.
- REMOVE name: Remove the student with the given name.
- UPDATE name grade: Update the grade for an existing student.
- AVERAGE: Output the average grade of all students. Use the formula \( \text{average} = \frac{\sum_{i=1}^{n} g_i}{n}\). If there are no students, output 0.
- HIGHEST: Output the highest grade among all students. If there are no students, output None.
- LOWEST: Output the lowest grade among all students. If there are no students, output None.
The operations are provided as sequential commands. Only the commands AVERAGE, HIGHEST, and LOWEST produce an output, each on a new line.
inputFormat
The first line contains an integer \( n \) indicating the number of commands. The following \( n \) lines each contain a command in one of the following formats:
ADD name grade
REMOVE name
UPDATE name grade
AVERAGE
HIGHEST
LOWEST
Note: name
is a string without spaces and grade
is an integer.
outputFormat
Whenever the command is AVERAGE
, output the average grade as a floating point number. For HIGHEST
and LOWEST
commands, output the corresponding integer grade. If there are no students in the collection at the time of the query, output 0
for AVERAGE
and None
for HIGHEST
and LOWEST
. Each output should be printed on a new line.
6
ADD Alice 90
ADD Bob 85
ADD Charlie 95
AVERAGE
HIGHEST
LOWEST
90.0
95
85
</p>