#K45422. Call Duration Aggregator
Call Duration Aggregator
Call Duration Aggregator
You are given several call records. Each record contains two names and a call duration. Both the caller and the recipient are credited with the call duration. Your task is to calculate the total call duration for each person and output the results as a dictionary with names as keys and their total call durations as values. The keys in the dictionary must be sorted in alphabetical order.
For example, if the input is:
5 Alice Bob 10 Bob Alice 15 Alice Charlie 20 Charlie Alice 5 Bob Charlie 30
Then the output should be:
{"Alice": 50, "Bob": 55, "Charlie": 55}
Note: All formulas, if any, should be in LaTeX format. In this problem, no formulas are needed.
inputFormat
The input is provided via stdin. The first line contains an integer \(N\) which specifies the number of call records. Each of the following \(N\) lines contains two strings and an integer separated by spaces: the caller's name, the recipient's name, and the call duration.
outputFormat
Print the resulting dictionary to stdout. The dictionary must have the names as keys (sorted alphabetically) and their corresponding total call durations as values. The dictionary should be in the following format:
{"Name": duration, ...}## sample
5
Alice Bob 10
Bob Alice 15
Alice Charlie 20
Charlie Alice 5
Bob Charlie 30
{"Alice": 50, "Bob": 55, "Charlie": 55}