#C5910. Review Manager Operations
Review Manager Operations
Review Manager Operations
You are required to implement a ReviewManager
that maintains a list of integer review scores and supports several operations. Initially, you are given a list of review scores. Then, a series of commands will be provided.
The supported operations are:
ADD s
: Add a new review with score \(s\).UPDATE idx s
: Update the review at index \(idx\) (0-indexed) to have the new score \(s\).DELETE idx
: Delete the review at index \(idx\) from the list.AVERAGE
: Calculate and output the average score of all reviews, rounded to two decimal places. If there are no reviews, output \(0.00\).COUNT s
: Output the number of reviews that have the exact score \(s\).
You must process the commands sequentially and output the result of any AVERAGE
and COUNT
operation to standard output.
inputFormat
The input is read from stdin and formatted as follows:
- The first line contains an integer \(N\), the number of initial review scores.
- The second line contains \(N\) space-separated integers representing the initial review scores.
- The third line contains an integer \(Q\), the number of operations.
- The next \(Q\) lines each contain one command. Each command is one of the following formats:
ADD s
UPDATE idx s
DELETE idx
AVERAGE
COUNT s
All numbers are integers. Indexing is 0-indexed.
outputFormat
For each AVERAGE
or COUNT
command, output the result on a new line to stdout. The average score must be rounded to two decimal places.
3
1 2 3
3
UPDATE 1 5
AVERAGE
COUNT 5
3.00
1
</p>