#C6455. Movie Collection Manager
Movie Collection Manager
Movie Collection Manager
You are given a set of commands to manage a collection of movies. Each movie has a title and a rating. Your task is to implement a program that processes the following commands:
- addMovie <title> <rating>: Adds a movie with the given title and rating to the collection. If the movie already exists, update its rating to the new value. The order of the first addition is preserved even if the rating is updated.
- getRating <title>: Returns the rating of the movie with the given title. If the movie does not exist, output
-1
. - getTopRatedMovie: Returns the title of the movie with the highest rating. If there are several movies with the same highest rating, return the one that was added earliest. If the collection is empty, output "No movies in collection".
The commands are given in order and should be executed one by one. Some commands require printing an output.
Note: All input should be read from standard input and all output should be written to standard output.
inputFormat
The first line contains an integer n
denoting the number of commands. The following n
lines each contain one command. Commands can be one of the following formats:
addMovie <title> <rating>
getRating <title>
getTopRatedMovie
Titles will be a single word (without spaces) and ratings are integers.
outputFormat
For each command that requires an output (getRating
and getTopRatedMovie
), print the result on a new line.
5
addMovie Inception 9
addMovie Interstellar 8
getRating Inception
getTopRatedMovie
getRating Avatar
9
Inception
-1
</p>