#K94772. Book Recommendation System
Book Recommendation System
Book Recommendation System
You are given a list of user preferences and a list of books. Each user preference consists of a genre and a rating (from 1 to 5) that indicates the user's affinity for that genre. Each book is described by its title, genre, and overall rating (a floating‐point number). A book is recommended if and only if:
(1) The user's preference rating for the book's genre is at least 3, i.e. . (2) The book's rating is at least 4.0, i.e. .
Among the recommended books, you must sort the list in descending order by rating. If multiple books have the same rating, they should be sorted in lexicographical (alphabetical) order by title.
Your program should read input from standard input and output the list of recommended book titles in a single line (titles separated by a comma and a space) to standard output. If no books qualify, output an empty line.
inputFormat
The input consists of multiple lines:
- The first line contains an integer P, the number of user preference entries.
- The next P lines each contain a genre (a string without spaces) and an integer rating (between 1 and 5), separated by a space.
- The following line contains an integer N, the number of books.
- The next N lines each describe a book in the format: title,genre,rating. The fields are separated by commas. The title and genre will not contain commas. The rating is a floating-point number.
outputFormat
Output a single line containing the recommended book titles separated by a comma and a space. If there are no recommended books, print an empty line.## sample
4
Science_Fiction 5
Fantasy 4
Mystery 3
Romance 2
6
Dune,Science_Fiction,4.8
The_Hobbit,Fantasy,4.6
The_Girl_with_the_Dragon_Tattoo,Mystery,4.1
Pride_and_Prejudice,Romance,4.4
Foundation,Science_Fiction,4.3
Twilight,Romance,3.9
Dune, The_Hobbit, Foundation, The_Girl_with_the_Dragon_Tattoo