The supermarket of the army

Simulate the behaviour of the queues of the supermarket of an army
headquarter. Initially, there are n queues (1, 2, …, n), each one with
its customers. Afterwards, two things can happen:

- A customer arrives to the queue: If the queue is between 1 and n, 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 n, 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.

Input

The input starts with the number of queues n (a natural strictly
positive). n 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.

Output

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 n 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 n is.

Autor: Salvador Roura

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T12:08:42.425Z

© Jutge.org, 2006–2026.
https://jutge.org
