#C4337. Total Revenue Calculation
Total Revenue Calculation
Total Revenue Calculation
You are given a series of transactions. Each transaction contains a product ID (a string), a quantity (an integer), and a price per unit (a float). The total revenue for a product is defined as the sum of quantity × price_per_unit across all transactions that involve the same product.
Your task is to compute the total revenue for each product. The revenue for each product should be rounded to two decimal places.
The formula used is: \(revenue = quantity \times price\_per\_unit\).
Print the result for each unique product sorted in ascending lexicographical order of product IDs. For each product, output a line containing the product ID and the corresponding revenue separated by a space.
inputFormat
The input is read from stdin and has the following format:
n transaction_1 transaction_2 ... transaction_n
The first line contains an integer n that specifies the number of transactions. Each of the following n lines contains a transaction, which has three fields separated by spaces:
- product_id (string)
- quantity (integer)
- price_per_unit (float)
outputFormat
For each unique product, print a single line containing the product id and its total revenue separated by a single space, where the revenue is rounded to two decimal places. The products must be printed in ascending lexicographical order of their product IDs.
The output is sent to stdout.
## sample5
P001 10 5.99
P002 1 299.99
P001 2 5.99
P003 5 19.99
P002 1 299.99
P001 71.88
P002 599.98
P003 99.95
</p>