#C8107. User Database Transaction Processor

    ID: 52053 Type: Default 1000ms 256MiB

User Database Transaction Processor

User Database Transaction Processor

You are given a sequence of queries to perform on a simple user database. The database supports the following four commands:

  • add_user <username>: Create a new user. Each username is unique.
  • add_transaction <username> <transaction_id> <amount>: Record a transaction for the given user. The transaction is identified by an integer transaction_id and has a monetary value amount.
  • get_total_transactions <username>: Return the total number of transactions recorded for this user.
  • get_total_amount <username>: Return the sum of all transaction amounts for this user. In mathematical terms, if the amounts for a user are \(a_1, a_2, \dots, a_n\), then the total is \(\sum_{i=1}^{n}a_i\).

The input is provided from the standard input (stdin) and the output should be written to the standard output (stdout). Only the commands get_total_transactions and get_total_amount produce output, and they should be printed in the order they are processed, each on a new line.

inputFormat

The first line contains an integer n representing the number of queries. The next n lines each contain one query. Each query is one of the following formats:

  • add_user <username>
  • add_transaction <username> <transaction_id> <amount>
  • get_total_transactions <username>
  • get_total_amount <username>

outputFormat

For each query that requests information (get_total_transactions or get_total_amount), output the result on a new line in the order in which the queries appear.

## sample
5
add_user Alice
add_transaction Alice 1 200
add_transaction Alice 2 300
get_total_transactions Alice
get_total_amount Alice
2

500

</p>