#K44027. Categorize Items
Categorize Items
Categorize Items
You are given a list of items where each item is given in the format type_item
(i.e. the item type and the item name separated by an underscore).
Your task is to categorize the items based on their type, sort the item names in each category in lexicographical order, and then output each category along with its sorted items. The categories themselves must be printed in lexicographical order.
The output format for each category is:
\( type:item1,item2,... \)
Each category appears on a new line. For example, if the input is:
6 weapon_sword potion_health armor_shield weapon_axe potion_mana armor_helmet
Then the correct output would be:
armor:helmet,shield potion:health,mana weapon:axe,sword
Note that the output uses LaTeX formatted inline math only to indicate formulas if needed.
inputFormat
The first line contains an integer \( N \) representing the number of items. The next \( N \) lines each contain a string of the format type_item
.
Input is read from stdin.
outputFormat
Print the categorized items such that each line contains a category followed by a colon and then a comma-separated list of sorted item names corresponding to that category. The categories must be printed in lexicographical order. The output is printed to stdout.
## sample6
weapon_sword
potion_health
armor_shield
weapon_axe
potion_mana
armor_helmet
armor:helmet,shield
potion:health,mana
weapon:axe,sword
</p>