#C4309. Calculate Total Sales by Category

    ID: 47833 Type: Default 1000ms 256MiB

Calculate Total Sales by Category

Calculate Total Sales by Category

You are given a list of transactions. Each transaction consists of a category name, a unit price, and a quantity sold. Your task is to calculate the total sales amount for each category.

The total sales for a category is computed as the sum over all transactions of (unit price × quantity) for that category. The output should list the categories in the order of their first appearance in the input along with their total sales, formatted to exactly two decimal places using the formula: \( \text{Total Sales} = \sum (\text{Unit Price} \times \text{Quantity}) \).

Read the input from stdin and output the results to stdout.

inputFormat

The first line of input contains an integer \( T \) representing the number of transactions. This is followed by \( T \) lines, each describing a transaction. Each transaction line contains a category name (a string without whitespace), a unit price (a float), and a quantity (an integer), all separated by spaces.

For example:

3
Electronics 199.99 2
Clothing 29.99 5
Electronics 99.99 4

outputFormat

For each unique category in the order they appear in the input, print one line containing the category name and the total sales for that category. The total sales must be formatted to two decimal places.

For example:

Electronics 799.94
Clothing 149.95
## sample
1
Electronics 199.99 2
Electronics 399.98

</p>