#K3326. Digital Wallet Simulation

    ID: 25048 Type: Default 1000ms 256MiB

Digital Wallet Simulation

Digital Wallet Simulation

In this problem, you are required to simulate a digital wallet system. The wallet supports several operations for managing user accounts and their balances. You need to implement the following operations:

  • CREATE_USER uid initial_balance: Create a new user with the given initial balance if the user does not already exist.
  • DEPOSIT uid amount: Deposit the given amount to the specified user's account.
  • WITHDRAW uid amount: Withdraw the given amount from the user's account if sufficient funds exist.
  • TRANSFER uid1 uid2 amount: Transfer the given amount from uid1 to uid2 if both users exist and uid1 has sufficient funds.
  • BALANCE uid: Print the current balance of the specified user if the user exists.

For each deposit, withdrawal, or transfer operation, the balance update can be represented as:

bnew=bold±amountb_{new} = b_{old} \pm amount

Input is provided via stdin and output should be sent to stdout.

inputFormat

The input starts with an integer n which denotes the number of operations. The following n lines each contain one operation in one of the following formats:

  • CREATE_USER uid initial_balance
  • DEPOSIT uid amount
  • WITHDRAW uid amount
  • TRANSFER uid1 uid2 amount
  • BALANCE uid

Note: uid is a string without spaces and amount as well as initial_balance are integers.

outputFormat

For every BALANCE operation that returns a valid result, print the balance (an integer) on a new line. If a BALANCE operation refers to a non-existent user, nothing is output for that operation.## sample

8
CREATE_USER Alice 5000
CREATE_USER Bob 3000
DEPOSIT Alice 2000
WITHDRAW Bob 500
TRANSFER Alice Bob 1000
BALANCE Alice
BALANCE Bob
TRANSFER Alice Charlie 3000
6000

3500

</p>