Collection of words P77859


Statement
 

pdf   zip

thehtml

Write a program to keep a collection of words. There are two instructions:

  • AFEGEIXw adds the word w to the collection, and prints nothing.
  • SEGUENT” deletes the longest word of the collection, and prints it. In the event of a tie, it deletes the word that was added first.

Input

Input consists of a sequence of instructions. The given words are made up of only lowercase letters, and can be repeated.

Output

For every “SEGUENT” instruction, print a line with the required word according to the rules given above. You can assume that there will always be at least one word.

Observation

“Afegeix” is Catalan for “add”, and “següent” is Catalan for “next”.

Public test cases
  • Input

    AFEGEIX hola
    AFEGEIX adeu
    SEGUENT
    AFEGEIX blabla
    SEGUENT
    SEGUENT
    

    Output

    hola
    blabla
    adeu
    
  • Input

    AFEGEIX a
    AFEGEIX bb
    AFEGEIX ccc
    AFEGEIX dddd
    SEGUENT
    AFEGEIX eee
    SEGUENT
    AFEGEIX bb
    SEGUENT
    AFEGEIX a
    SEGUENT
    SEGUENT
    

    Output

    dddd
    ccc
    eee
    bb
    bb
    
  • Information
    Author
    Enric Rodríguez
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++