#C13339. Categorize Transactions
Categorize Transactions
Categorize Transactions
You are given a list of financial transactions. Each transaction contains an amount (a positive integer), a type (either "income" or "expense"), and a category (a string without spaces). Your task is to compute, for each category, the total income and total expenses, and then determine the net balance. The net balance is computed as: \(\text{net} = \text{income} - \text{expense}\).
The results must be printed in lexicographical order of the category names. If there are no transactions, do not output anything.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains a single integer \(n\) representing the number of transactions.
- The following \(n\) lines each contain three space-separated elements: an integer amount, a string type (either "income" or "expense"), and a string category.
Note: The category does not contain spaces.
outputFormat
For each unique category, output a line containing four space-separated elements: the category name, the total income, the total expense, and the net balance. The categories must be printed in lexicographical order.
If there are no transactions, output nothing.
## sample2
1000 income salary
450 income salary
salary 1450 0 1450
</p>