[ad_1]
FoodFlop is a new delivery service in the age of Covid-19. No longer allowed to bring food items directly to
customers in person, this service has a trademark routine where the food is “flopped” (with extra dramatic flair)
onto the porch for a contactless delivery.
You’ve been asked by FoodFlop to write a program that can optimize the delivery operations of its team of
drivers. There are a few constraints that must be met:
The food is arranged in the delivery car such that only the most recent pickup is available for delivery (in other
words, LIFO order). For example, if items A, B, and C were picked up in that order, the next delivery must be C,
then B, then A.
Any number of deliveries can be made. The food is kept hot (or cold) by special packaging and can be kept in
the car indefinitely.
At the end of the route, all of the food that was picked up must have been delivered.
Write a program that accepts a series of proposed “pickups” and “dropoffs” as input, and outputs whether or
not the proposed series is valid. View the below video for some ideas on getting started.
There are only five restaurants in this small town, identified as follows:
Applebee’s
Burger King
Chipotle
Domino’s Pizza
El Pollo Loco
The input file (a text file) is a series of proposed pickup and dropoff sequences which should be independently
verified. Each sequence starts with an empty stack and is formatted in the file as follows:
At the beginning of a new sequence, the number of lines in that sequence is given (a single integer by itself,
this will be at least 1).
A pickup – labeled with a 1 followed by a letter (A, B, C, D or E for short).
A dropoff – labeled with a 2 followed by a letter.
Example:
This input file has 5 separate series which should be verified independently of each other.
4
1 B
1 A
2 A
2 B
8
1 A
1 B
1 C
2 C
2 B
1 D
2 D
2 A
3
1 D
1 A
2 A
4
1 B
1 C
2 B
2 C
2
1 E
2 E
Output
Your program should output, for each series of pickups and dropoffs, whether this is a valid series, which is
true if:
2/10/2021 Order 336433356
https://admin.writerbay.com/orders_available?subcom=detailed&id=336433356 3/3
The series can be accomplished, given the constraints, and
All of the food is delivered (the car is empty) at the end of the series
If both of these are true, the series is valid, otherwise it is not valid.
You program should output only ‘valid’ or ‘not valid’, one line per test case. Be sure to turn off any extra cout or
debugging statements.
For the example input file above (which has 5 separate series) here is the correct output:
valid
valid
not valid
not valid
Sample Solution
The post FoodFlop appeared first on acestar tutors.
[ad_2]
Source link