#C14548. Grade Manager Operations
Grade Manager Operations
Grade Manager Operations
You are given a grade manager that supports various operations on a list of integer grades. Initially, you are provided with a list of grades. Then, a series of commands are given as input. You are required to implement the operations accordingly.
The supported commands are:
add X
: Add grade X to the list.remove X
: Remove grade X from the list. If X is not in the list, output an error message in the form: \(\texttt{Grade X not found in the list.}\)sort
: Sort the list in ascending order.max
: Output the highest grade. If the list is empty, outputNone
.min
: Output the lowest grade. If the list is empty, outputNone
.avg
: Compute and output the average of the grades. If the list is empty, output 0.count T
: Count and output the number of grades strictly greater than threshold T.
Input is taken from stdin and outputs should be printed to stdout.
The input format is as follows:
- The first line contains an integer \(N\) representing the number of initial grades. If \(N = 0\), the list is empty.
- The second line contains \(N\) space-separated integers representing the initial grades. This line may be empty if \(N = 0\).
- The third line contains an integer \(Q\) representing the number of commands.
- The next \(Q\) lines each contain one command as described above.
Output the result for each command that produces an output in the order they are processed.
inputFormat
The input begins with an integer \(N\) specifying the number of initial grades. The next line contains \(N\) integers (if \(N \gt 0\)), followed by an integer \(Q\) which indicates the number of commands. Each of the following \(Q\) lines contains one command.
outputFormat
For each query command that expects an output (max
, min
, avg
, count
or error output from remove
), print the result on a new line to stdout in the order in which the commands are executed.
3
85 92 76
2
add 90
max
avg
92
85.75
</p>