#C936. Movie Rater
Movie Rater
Movie Rater
You are given a series of operations to manage movie ratings. There are four operations:
- ADD <movie_name>: Add a movie with the given name if it does not exist.
- RATE <movie_name> <score>: Rate the given movie with an integer score such that \(1 \leq score \leq 5\). If the movie does not exist or the score is invalid, print
error
. - AVG <movie_name>: Output the average rating of the specified movie (as a floating point number). If the movie does not exist, print
error
. If the movie has no ratings, its average is considered as 0.0. - HIGHEST: Output the name of the movie with the highest average rating. In case of a tie, output the movie that was added earlier. If no movies exist, print
error
.
You are to process a sequence of commands provided from standard input. The first line contains an integer \(T\) representing the number of operations. Each of the following \(T\) lines contains one command. All outputs should be printed to standard output.
inputFormat
The first line contains an integer \(T\) (the number of operations). The next \(T\) lines each contain a command in one of the following formats:
ADD movie_name
RATE movie_name score
AVG movie_name
HIGHEST
Note that movie names will not contain spaces, and score is an integer.
outputFormat
For each command that requires an output (AVG
and HIGHEST
), print the result on a new line. In case any operation results in an error (such as rating a non-existent movie or an invalid score), print error
on a new line.
5
ADD The_Matrix
RATE The_Matrix 5
AVG The_Matrix
ADD Inception
HIGHEST
5.0
The_Matrix
</p>