This problem was used in the following GFU competitions:
GFU 2024 D3 Q8
GFU 2024 D2 Q1
You are finally allowed back in the Underground Kitchen... as a prep cook. However, Ramsey Gordon has told you that if you properly organize his spice cabinet, you may be able to work your way back into dinner service.
The first line will contain a single integer n that represents the number of data sets that follow. Each data set will contain the spice name, an integer m denoting the amount of the spice, and a rating of 1-5 denoting how often it is used (5 being the most, 1 the least), and finally the color of the spice.
Sort first by how often they are used, with 5 coming first and 1 last.
Then sort by color, with the preference chart for color being (colors appear as below, same capitalization) :
1) White
2) Red
3) Brown
4) Orange
5) Blue
6) Other (not the word other, just any other color)
Then sort by how much you have, with the spices you have more of coming first.
Then sort by name, alphabetically.
There will be none equal after all these checks.
Output the spice names in sorted order based on the above sorting method.
Example Input:
4
Paprika 7 2 Red
Cumin 12 3 Brown
Sugar 8 3 White
Salt 3 5 White
Example Output:
Salt
Sugar
Cumin
Paprika
Use Dictionaries to simplify sorting