#C8307. Transaction Summarizer
Transaction Summarizer
Transaction Summarizer
You are given a series of financial transactions in which each transaction is recorded in the format CATEGORY:AMOUNT
. Your task is to aggregate the amounts for each category and then output the results. Specifically, for every distinct category, sum the amounts and display the total in the format CATEGORY:TOTAL_AMOUNT
with the total rounded to two decimals. The output should list categories in lexicographical order.
If there are no transactions (i.e., the number of transactions is 0), simply output NO TRANSACTIONS
.
Mathematical Note: If you let \( a_i \) represent the amount of the \( i \)-th transaction for a given category, then the total is \( \sum_{i=1}^{k} a_i \) and should be formatted as \( \text{TOTAL_AMOUNT} = \texttt{%.2f}(\sum_{i=1}^{k} a_i) \).
inputFormat
The input begins with an integer ( n ) on the first line, representing the number of transactions. The next ( n ) lines each contain a transaction in the format CATEGORY:AMOUNT
.
outputFormat
Print the summarized transactions. Each line should contain a category and its total summed amount (rounded to two decimal places) in the format CATEGORY:TOTAL_AMOUNT
. Categories must be printed in lexicographical order. If ( n = 0 ), output NO TRANSACTIONS
.## sample
5
food:100.50
transport:-20.25
food:50.75
entertainment:200.00
transport:5.00
entertainment:200.00
food:151.25
transport:-15.25
</p>