13904 - Top-3 Genre   

Description

A movie streaming platform has a list of movies, each with multiple genres and a user rating. Your task is to analyze the given data and find the top 3 genres with the highest average rating across all movies. Additionally, calculate the average rating for each genre.

 

Input

A multi-line string, where each line represents a movie's title, genres, and user rating, separated by commas. The movie's title is a string, genres are lowercase letters (a-z) separated by a vertical bar (|), and the user rating is a float. The number of lines in the input is n (1 ≤ n ≤ 10^4), and the user rating is in the range of [0, 10].

 

 

Output

A multi-line string, where each line represents the genre and its average rating. The output should include only the top 3 genres with the highest average ratings.

  1. If two genres have the same average rating, sort them by their genre names in ascending order(from a to z).
  2. The score should have 2 decimals. (truncate to the second decimal place, elaborate below)

 

Noted, If you directly use %.2f to cut the number, the number will be rounded up.

For example:

eg = 7.9775609756097534

formatted_eg = String(format: "%.2f", eg)

formatted_eg will be 7.98 instead of 7.97

 

Here is the hint you can use in your code

number = 7.9775609756097534 
truncated_number = int(number * 100) / 100
truncated_number = "{:.2f}".format(truncated_number)

print(truncated_number) // truncated_number will be 7.97

Sample Input  Download

Sample Output  Download

Tags




Discuss