#C1098. Calculate Total Revenue
Calculate Total Revenue
Calculate Total Revenue
You are given sales records for various product categories. Each record contains three fields: an ID, a category name, and a sale amount. Your task is to compute the total revenue for each category and output them sorted in lexicographical order. The total revenue for each category is the sum of all sale amounts (rounded to two decimal places).
In mathematical terms, for each category \( C \), compute:
\( \text{total}_C = \sum_{i \in C} \text{amount}_i \)
and output the result as category: total
where total
is formatted to two decimals.
inputFormat
The first line contains a non-negative integer \( n \) indicating the number of sales records.
Each of the following \( n \) lines contains a sales record in the following format:ID, category, amount
where the fields are separated by a comma and a space. The ID
is an integer, category
is a string, and amount
is a decimal number.
outputFormat
For each category that appears in the input, output one line in the following format:category: total
where total
is the sum of all sale amounts for that category rounded to two decimal places. The output lines must be sorted in lexicographical order by the category name.
5
1, electronics, 200.00
2, groceries, 50.00
3, electronics, 100.00
4, clothing, 150.00
5, groceries, 100.00
clothing: 150.00
electronics: 300.00
groceries: 150.00
</p>