#C279. Product Recommendations
Product Recommendations
Product Recommendations
You are given a list of product categories along with their corresponding interest scores. Your task is to sort the product categories in descending order by their scores. If two or more categories have the same score, they should be sorted in alphabetical order. The result should be output as a single line containing the sorted product category names separated by a single space.
Note: Input is read from standard input (stdin) and the result should be printed to standard output (stdout). If you are using a language that requires explicit reading and writing of inputs and outputs, please adhere to these methods.
The problem can be mathematically represented by the following criteria:
[ \text{Sort items } (c, s) \text{ such that } (c_1, s_1) \text{ comes before } (c_2, s_2) \iff s_1 > s_2 \text{ or } (s_1 = s_2 \text{ and } c_1 < c_2). ]
inputFormat
The first line of the input contains a single integer N
(1 ≤ N ≤ 105), which represents the number of product categories.
Then follow N
lines, each containing a product category and its interest score separated by a comma. The product category is a string (which may contain spaces and symbols) and the interest score is an integer.
Example:
4 Electronics,85 Books,75 Clothing,90 Home & Kitchen,85
outputFormat
Output a single line containing the product categories sorted based on the given criteria. The categories should be separated by a single space.
For the sample input above, the output should be:
Clothing Electronics Home & Kitchen Books## sample
4
Electronics,85
Books,75
Clothing,90
Home & Kitchen,85
Clothing Electronics Home & Kitchen Books