#C10704. Categorizing Movies by Genre

    ID: 39939 Type: Default 1000ms 256MiB

Categorizing Movies by Genre

Categorizing Movies by Genre

You are given a list of movies, where each movie is represented by a JSON object containing the keys title (a string), genre (a string), and rating (a float). Your task is to categorize these movies by their genre. For each genre, output a list of movie titles sorted in descending order by their rating. If two movies have the same rating, they should retain the order in which they appear in the input.

Note: The rating comparison follows the rule: \(a \text{ is ranked higher than } b\) if \(rating(a) > rating(b)\).

inputFormat

The input is provided as a single line from standard input (stdin) in JSON format. It contains a JSON array of movie objects. Each object has the following structure:

{
  "title": "Movie Title",
  "genre": "Genre Name",
  "rating": RatingValue
}

outputFormat

The output should be a JSON dictionary printed to standard output (stdout). Each key in the dictionary is a movie genre and the corresponding value is a list of movie titles sorted by descending rating. For example:

{
  "Action": ["Movie C", "Movie A"],
  "Horror": ["Movie D", "Movie B"]
}
## sample
[{"title": "Movie A", "genre": "Action", "rating": 8.5}, {"title": "Movie B", "genre": "Horror", "rating": 7.2}, {"title": "Movie C", "genre": "Action", "rating": 9.1}, {"title": "Movie D", "genre": "Horror", "rating": 8.0}]
{"Action":["Movie C","Movie A"],"Horror":["Movie D","Movie B"]}