Code Wars II
Danger Level: Black
Point Value: 14
Did somebody say McFood? This problem is all about your McFood!
It seems the bigwigs at McFood want
to study how people respond to long lines in their restaurants, and you're
going to help them by writing a program to simulate people getting in line
and ordering McFood. No cutting in line, now...
There are two input files associated with this problem. The first file, MCFOOD.DAT, is a data file listing all the McFood items available to order. Each item is listed by name along with the average amount of time required to retrieve that McFood item in seconds.. Here are some example lines from that file:
ITEM=McPeanut Butter Sandwich;TIME=39
The second input file specifies (1) the number of lines to simulate, (2) the people who enter the restaurant (patrons), (3) the time at which each patron enters, and (4) what McFood each patron orders.
The exact format is as follows: The first line indicates the number of lines to simulate in the restaurant. This number may vary between 1 and 10, inclusive. The remaining file is separated into time segments divided by lines with the text TIME=N. After an individual TIME=N line, each patron is listed who is to enter the restaurant at that time. One or more people may be specified for this time. Thereafter the file may contain another TIME=N line, followed by more patrons, indefinitely. the value of N in the line TIME=N is measured in tens of seconds; that is, TIME=2 means "at the time 20 seconds after the beginning of the simulation." The simulation begins at TIME=0 (zero).
Each patron record is started with a NAME=qqq line, where qqq is the patron's name. This is followed by on or more lines of ITEM=xxx;COUNT=c, indicating an item the patron wishes to order, followed by the number of those items. Here's an example input file:
The program should print the name
of each patron to separate line in the output file PROB16.OUT. Each
output line should also include which McFood line served the patron, and
1. the patron's wait time, in minutes & seconds, from restaurant entry to transaction completion, and
2. the simulation's clock time, in seconds, at transaction completion.
The output lines should appear in the output file sorted by simulation clock time.
Because items can be retrieved in
parallel, you should subtract 10 seconds from the total time required for
each item above one that an individual patron orders. (i.e., 2 items
means subtract 10 seconds, 3 items means 20 seconds, etc.) If the
patron orders a McFood item that the restaurant doesn't serve, then ignore
the item, but add fifteen seconds for the delay from the confusion.
To account for the time required to place the order, add an additional
7 seconds for each ITEM=xxx line for that patron (regardless of the item
Finally, add another 17 seconds to pay for the McFood.
If a line becomes empty while another
line has more than one patron, the patron at the end of the longest line
moves to the empty line. In the case of two lines tied for longest,
select the patron from the highest numbered line, i.e., line 5 over line
2. Upon entry into the restaurant, patrons should be assigned to
a line according to these rules:
1. the patron first chooses the shortest line.
2. if two or more lines are equal in length, the patron chooses the line with the lowest number. i.e., she chooses line 2 over line 5.
Here is the output for the above sample input file:
Vaneesha was served in line 2; wait
time = 0:58; sim time = 58s
Hyung was served in line 2; wait time = 1:52; sim time = 182s
Kathleen was served in line 3; wait time = 2:47; sim time = 187s
Bill was served in line 1; wait time = 3:34; sim time = 214s
Piotr was served in line 2; wait time = 1:46; sim time = 288s