#K82707. Reorder Inventory Items
Reorder Inventory Items
Reorder Inventory Items
You are given a list of inventory items. Each item has a name (a string) and a quantity (an integer). Your task is to reorder these items in descending order based on their quantities. If two items have the same quantity, they should be sorted in alphabetical order (ascending) by their names.
The input will start with an integer n (the number of items), followed by n lines each containing an item's name and its quantity. The output should list the items in the sorted order, with each line containing the item name and quantity separated by a space.
This problem assesses your ability to perform custom sorting based on multiple criteria.
inputFormat
The first line of the input contains an integer n representing the number of inventory items. Each of the next n lines contains a string and an integer separated by a space, representing the name and quantity of an item respectively.
Example:
4 apple 10 banana 5 pear 10 grape 5
outputFormat
Print the sorted inventory items, one per line. Each line should contain the item name and its quantity separated by a single space.
For the sample input above, the output should be:
apple 10 pear 10 banana 5 grape 5## sample
0