Skip to content

baconeggsandspam

bradendubois edited this page Oct 7, 2021 · 8 revisions

Bacon, Eggs, and Spam

ID: baconeggsandspam

Difficulty: 1.8

CPU Time: 1 second

Memory: 1024 MB

Solution

For this, one can take in the n lines for each case, and register the first word in the line as a name, and all the subsequent words in the line as items. A map from each item to a list of all those who ordered them item is necessary, and one could keep a list of all the unique items, to output them all later (or access the keyset of that map). For every item in that line, add the name to those respective item lists, and if any of these lists are empty, add this item to the list of unique items. After processing, one can sort the list of items and iterate through them, and at each item, get its list of patrons and sort those. Output the item, and every patron.

Clone this wiki locally