#K42477. Consolidating Items
Consolidating Items
Consolidating Items
You are given a list of items, each represented as a tuple consisting of an item code, a name, and a unique identifier (uid). Your task is to consolidate items that have the same item code and name by concatenating their uids.
For each group of items, sort the uids in lexicographical order and concatenate them with a hyphen ('-') as the separator. Mathematically, if the sorted uids for a group are \(u_1, u_2, \dots, u_k\), then the concatenated string should be \(u_1 - u_2 - \cdots - u_k\).
The order of the output lines does not matter.
inputFormat
The input is read from stdin and begins with an integer (n) representing the number of items. Each of the following (n) lines contains three space-separated strings: item_code, name, and uid.
outputFormat
The output should be written to stdout. For each unique item (identified by a combination of item_code and name), print a single line with the item_code, name, and the concatenated sorted uids separated by hyphens. The order of the output lines does not matter.## sample
5
item1 apple 001
item2 banana 002
item1 apple 003
item3 cherry 004
item2 banana 005
item1 apple 001-003
item2 banana 002-005
item3 cherry 004
</p>