#K76907. Top Selling Products by Category
Top Selling Products by Category
Top Selling Products by Category
You are given a list of products, where each product is described by a name, a category, and its sales (an integer). Your task is to determine the top-selling product in each category and output the results in sorted order by category name.
Details:
- Each input begins with an integer n which represents the number of products.
- Then follow n lines, each containing three fields: the product's name, its category, and its sales (an integer). The fields are separated by spaces.
- If two products in the same category have equal sales, the product that appears first in the input is considered the top-selling product.
- The output should list each category and the corresponding top-selling product in the following format:
category: product
, one per line, in lexicographically increasing order of the category name.
No advanced mathematical formulas are needed, but if you encounter any mathematical expressions, please note that they should be formatted in LaTeX (for example, $a+b=c$).
inputFormat
The first line of input contains an integer n representing the number of products. Following this, there are n lines, each containing a product's name (a single word), category (a single word), and sales (an integer), separated by spaces.
outputFormat
For each unique category, output a line in the format category: product
, where product
is the top-selling product of that category. The categories should be printed in lexicographical (alphabetical) order.
3
ProductA Electronics 150
ProductB Electronics 200
ProductC Electronics 120
Electronics: ProductB
</p>