#K86442. Product Recommendation System
Product Recommendation System
Product Recommendation System
You are given a catalog of products and a list of categories for which recommendations should be generated. Each product has a name, category, average rating, and number of sales. Your task is to recommend products based on the following criteria:
- For each recommended category, consider only the products that belong to that category.
- Sort the products in descending order of average rating. In case of a tie, sort by descending number of sales. If there is still a tie, sort by product name in lexicographical order (i.e. ascending order).
The output for each category should first display the category name, followed by the list of recommended products where each product is displayed on a separate line in the format: . Consecutive categories are separated by an empty line.
All formulas should be written in LaTeX format if needed. For example, the sorting criteria on average rating can be expressed as , on number of sales as , and lexicographically by the product name.
Your solution should read from standard input (stdin) and print the result to standard output (stdout).
inputFormat
The input is given via stdin and has the following format:
- The first line contains an integer , the number of categories.
- The following lines each contain a unique category name.
- The next line contains an integer , the number of products.
- The following lines each describe a product in the format:
- The next line contains an integer , the number of recommended categories.
- The following lines each contain a category name for which recommendations are needed.
outputFormat
For each recommended category that has one or more products, output the category name on a separate line, followed by its recommended products. Each product is printed on a new line in the format:
Separate the output for different categories with an empty line. Do not print an extra empty line after the final category.## sample
3
Electronics
Home_Appliances
Books
6
TV Electronics 4.5 2000
Blender Home_Appliances 4.2 1500
Laptop Electronics 4.8 1800
Oven Home_Appliances 4.7 1600
Book1 Books 4.9 2200
Book2 Books 4.8 2100
3
Electronics
Books
Home_Appliances
Electronics
Laptop 4.8 1800
TV 4.5 2000
Books
Book1 4.9 2200
Book2 4.8 2100
Home_Appliances
Oven 4.7 1600
Blender 4.2 1500
</p>