Simulate the behaviour of the queues of the supermarket of an army headquarter. Initially, there are queues (), each one with its customers. Afterwards, two things can happen:
A customer arrives to the queue: If the queue is between 1 and , the customer enters in the queue. Otherwise, the event is ignored.
A customer goes out of the queue: If the queue is between 1 and , and the queue is not empty, the customer with highest graduation goes out of the queue. In a event of a tie, goes out the one who arrived first. Otherwise, the event is ignored.
The input starts with the number of queues
(a natural strictly positive).
lines follow, one per line, each one with its customers (a word) and
their graduations ("soldier", "sergeant",
"captain", or
"colonel"), in the order that they have
arrived to que queue. After a line in white comes and a series of
events, one per line: the word "ENTER" followed by the
customer, the graduation, and the queue which he arrives to, or the word
"LEAVE" followed by the queue which he leaves.
First, your program must print the name of the customers that leave the queues, in the order that they left. After, it must print the final content of the queues, each one from the beginning to the end. Follow the format of the instance.
Hint: Use the instructions
getline(cin, st) (where st is a string) to
read a line, and istringstream iss(st); to create a stream
iss which you can read the names and graduations from,
iss nam gra;,
where nam and gra also are strings. Be careful
with the first getline you do, that will correspond to the
line where the number
is.
Autor: Salvador Roura
Input
4 Cristina soldier Tomas captain Francesc sergeant Damia soldier Domenec colonel Teresa captain Toni sergeant Carles captain LEAVE 1 LEAVE 1 ENTER Amalia sergeant 4 ENTER Pep soldier 4 LEAVE 2 LEAVE 1 ENTER Leo captain 1 ENTER Maria sergeant 4 LEAVE 4 LEAVE 4 LEAVE 4 ENTER Carme soldier 4 LEAVE 2 LEAVE -1 LEAVE 2
Output
LEAVINGS ------- Tomas Cristina Domenec Teresa Carles Toni Francesc Damia FINAL CONTENT ------------------ queue 1: Leo queue 2: queue 3: queue 4: Amalia Maria Pep Carme