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.
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].
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.
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