#K33862. Aggregate Sales by Author
Aggregate Sales by Author
Aggregate Sales by Author
You are given a list of sales records, each in the following format:
author,sale
where author
is the name of an author and sale
is an integer representing the sales figure. Your task is to aggregate (sum up) the sales for each author and then output the result.
The output should list each author along with their total sales in the format:
author,total_sale
The list must be sorted primarily by the total sales in descending order and then by the author's name in alphabetical order in case of ties.
Note: If there are no records, the program should output nothing.
The mathematical representation of the aggregation can be given as follows:
\( total\_sale(a) = \sum_{i=1}^{n} sale_i \quad \text{for each record with author } a \)
inputFormat
The first line of the input contains a single integer N
(0 ≤ N ≤ 105), representing the number of sales records.
The following N
lines each contain a sales record in the format author,sale
.
It is guaranteed that sale
is a valid integer and the author
contains no commas.
outputFormat
For each distinct author found in the input, output a single line in the format author,total_sale
, where total_sale
is the aggregated sales of that author.
The output should be sorted in descending order of total sales and (if there is a tie in sales) in alphabetical order by the author's name.
## sample6
John Doe,5
Jane Smith,3
John Doe,7
Jane Smith,1
John Doe,2
Jane Smith,4
John Doe,14
Jane Smith,8
</p>