Balances P23318


Statement
 

pdf   zip

html

Given a sequence of triplets formed by two names x and y and a natural n, that indicate that x has paid n euros to y, print the final balance of each person, first sorted by name, and then sorted by balance.

Input

Input is a non empty sequence of triplets formed each one by two names and a natural. There are not two people with the same name.

Output

Your program must print the final balance of each person, first sorted by name, and then sorted by balance, separated by a line with twenty dashes. In the event of a tie in the balance, it must print first the smallest name.

Public test cases
  • Input

    john mary 1000
    peter john 20000
    mary anna 1000
    emma anna 5000
    peter michael 4000
    peter paul 0
    anna michael 1000
    

    Output

    anna 5000
    emma -5000
    john 19000
    mary 0
    michael 5000
    paul 0
    peter -24000
    --------------------
    peter -24000
    emma -5000
    mary 0
    paul 0
    anna 5000
    michael 5000
    john 19000
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++
    User solutions
    C++ Java