Gossip P47386


Statement
 

pdf   zip

thehtml

Write a program to maintain basic information for the gossip magazines: who is a couple of who. There are two kinds of orders: “info” and “affairx y. The first asks for a list of all the information at that moment. The second indicates that x and y are a couple now. If some person z was a couple of x or a couple of y, then z becomes single.

Input

Input consists of several orders. For every “affairx y order, both x and y are words made up of only lowercase letters, such that x and y are different, and such that x and y do not have an affair at that moment.

Output

Print as many lists as “info” orders, finishing each with a line with 10 dashes. Print the couples in alphabetical order, and also the couples among them. Print the alone people in alphabetical order as well.

Observation

In the private test cases, most orders are of the “affair” kind.

Public test cases
  • Input

    affair gerard shakira
    info
    affair sara iker
    info
    affair gerard sara
    info
    affair iker cristiano
    info
    

    Output

    COUPLES:
    gerard shakira
    ALONE:
    ----------
    COUPLES:
    gerard shakira
    iker sara
    ALONE:
    ----------
    COUPLES:
    gerard sara
    ALONE:
    iker
    shakira
    ----------
    COUPLES:
    cristiano iker
    gerard sara
    ALONE:
    shakira
    ----------
    
  • Input

    info
    affair ba a
    affair b ab
    affair aab ac
    info
    affair ac b
    affair b ab
    info
    

    Output

    COUPLES:
    ALONE:
    ----------
    COUPLES:
    a ba
    aab ac
    ab b
    ALONE:
    ----------
    COUPLES:
    a ba
    ab b
    ALONE:
    aab
    ac
    ----------
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Salvador Roura
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Python