#K85207. Summarize Employee Expenses
Summarize Employee Expenses
Summarize Employee Expenses
You are given a list of expense records for employees. Each record contains three fields: the employee ID, the trip type, and the expense amount. The trip type is a string that can be either business or leisure. Your task is to calculate the total expense for each type per employee and then print the summary sorted by employee ID in ascending order.
You can mathematically express the problem as follows: \[ TotalExpense_{i,t} = \sum_{j \in R(i,t)} a_j \] where \(i\) denotes the employee ID, \(t\) is the trip type, and \(a_j\) represents the expense amount for record \(j\) corresponding to employee \(i\) and type \(t\). If an employee does not have any expense for a particular trip type, consider its total as 0.
inputFormat
The first line of input contains a single integer \(n\) which represents the number of expense records. Each of the following \(n\) lines contains three space-separated values: an integer corresponding to the employee ID, a string representing the trip type (either business
or leisure
), and an integer indicating the expense amount.
outputFormat
For each unique employee ID, output one line in the following format: employee_id business:X leisure:Y
, where X
is the total business expense and Y
is the total leisure expense for that employee. The records should be sorted in ascending order by the employee ID.
5
1 business 200
2 leisure 300
1 leisure 150
3 business 100
2 business 400
1 business:200 leisure:150
2 business:400 leisure:300
3 business:100 leisure:0
</p>