#K88692. Genre Popularity Recommendation System
Genre Popularity Recommendation System
Genre Popularity Recommendation System
This problem requires you to build a recommendation system that analyzes the popularity of different movie genres based on user preferences. Each user’s preference is provided as a line containing the number of genres the user likes, followed by the actual genre names. Your task is to:
- Parse the input from the standard input.
- Count the occurrences of each genre across all users.
- Sort the genres by their popularity (in descending order) and lexicographically (in ascending order) if two genres have the same popularity.
- Print the sorted results to the standard output.
The sorting criteria can be expressed mathematically as follows:
For two genres \(a\) and \(b\) with counts \(c_a\) and \(c_b\), \(a\) comes before \(b\) if either \(c_a > c_b\) or \(c_a = c_b\) and \(a < b\) in lexicographical order.
inputFormat
The input is read from standard input (stdin) and has the following format:
N c1 genre1 genre2 ... c2 genre1 genre2 ... ...
Where:
- N is an integer representing the number of users.
- Each of the following N lines starts with an integer ci indicating the number of genres that follow for the i-th user, followed by exactly ci genre names.
outputFormat
Output the list of genres along with their popularity count to the standard output (stdout). Each line should contain a genre and its count separated by a single space. The genres must be sorted by descending popularity, and in case of ties, sorted lexicographically in ascending order.
genre1 count1 genre2 count2 ...## sample
5
3 action comedy drama
2 action horror
4 comedy drama thriller action
1 thriller
2 drama thriller
action 3
drama 3
thriller 3
comedy 2
horror 1
</p>