#C14754. Transaction Sum Filter
Transaction Sum Filter
Transaction Sum Filter
You are given a list of transactions and a current date. Each transaction is represented by a triple consisting of a user_id
(a string), a date
in the format YYYY-MM-DD
, and an amount
(a float). Your task is to filter out those transactions that occurred within the last month, and then compute the total transaction amount for each user. Here, the last month is defined as the period between \(current\_date - 30\ \text{days}\) and \(current\_date\) (inclusive).
Note: A transaction with date \(d\) is considered if and only if \(one\_month\_ago \leq d \leq current\_date\), where \(one\_month\_ago = current\_date - 30\,days\).
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(n\), the number of transactions.
- The next \(n\) lines each contain a transaction in the format:
user_id date amount
, wheredate
is in the formatYYYY-MM-DD
andamount
is a floating point number. - The last line contains the
current_date
in the formatYYYY-MM-DD
.
outputFormat
For each user who has at least one transaction in the last month (i.e. between current_date - 30 days
and current_date
inclusive), output a line containing the user_id
and their total transaction sum, separated by a space. The output should be sorted in ascending lexicographical order of user_id
. If no transactions fall within the last month, output nothing.
0
2023-10-17