The supermarket of the army P95523


Statement
 

pdf   zip

thehtml

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

Public test cases
  • 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
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Spanish
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++