Honest politicians P80094


Statement
 

pdf   zip

html

In a distant country, judges are busy trying to find out how much money several politicians have earned as the result of some money movements. There are three kinds of transactions:

  • R name number: Politician name receives number money (from some unknown bank).
  • G name number: Politician name gives number money (to some unknown relative).
  • P name1 number name2: Politician name1 pays number money to politician name2, where name1 and name2 are different.

Could you please compute the final earnings of every politician?

Input

Input consists of several cases. Each case begins with a natural number r. Follow between 1 and 104 transactions. Every case ends with “END”. You can assume that r is between 1 and the number of different names in the case, that all the names are strings made up of an uppercase letter followed by between 1 and 10 lowercase letters, and that all given numbers are natural numbers between 1 and 105.

Output

For every case, print r rows with the name and the final money of every politician. Names should be alphabetically sorted by columns. Every column has to be as narrow as possible, with names aligned to the left, money aligned to the right, and at least one space separating them. Separate columns with a vertical bar surronded by two spaces. The last column may be partially empty: always leave those empty positions at the bottom of the column. Print a line with 40 ‘*’ after every case. Take a look at the sample output to exactly follow its format. Note that no line should end with any space.

Public test cases
  • Input

    2
    R Smith 1000
    G Taylor 20000
    END
    
    1
    P Taylor 20000 Smith
    END
    
    3
    P Blue 3 Red
    G Brown 100000
    R Blue 3
    R Orange 5000
    P White 1 Blonde
    R Pink 12345
    END
    

    Output

    Smith    1000
    Taylor -20000
    ****************************************
    Smith 20000 | Taylor -20000
    ****************************************
    Blonde      1 | Orange 5000 | White -1
    Blue        0 | Pink  12345
    Brown -100000 | Red       3
    ****************************************
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++
    Event
    Onzè Concurs de Programació de la UPC - Semifinal
    Date
    2013-06-19