Under construction

Still being built. Things may change

Transaction Processing

Time limit1sMemory limit128 MB

Summary
Read ledger accounts and transaction entries, then print an exception report for any transaction whose debits and credits do not sum to zero.
Level

Easy3 of 10

Topics
Implementation, Hash map, Simulation, Brute force
Solved
No attempts yet

Problem

Write a program that performs one of the initial steps in posting transactions to a general ledger.

The central principle of double-entry bookkeeping is that the sum of all debits must equal the sum of all credits, and this must hold for every transaction.

In this program, positive numbers represent debits and negative numbers represent credits. For example, 2.00 is a two-dollar debit and -2.00 is a two-dollar credit.

The goal of the program is to check whether each transaction balances and to report any transaction that does not.

Input

The input has two parts.

The first part is the list of general-ledger accounts: up to 100 accounts, one per line, in the format

nnnxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

where nnn is a three-digit account number and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is a 1-to-30 character account name. This part ends with a record that starts with 000, which is never used as an account number.

The second part consists of 15-character records, one per line, in the format

sssnnnxxxxxxxxx

where sss is a three-digit sequence number, nnn is a three-digit account number, and xxxxxxxxx is a nine-digit amount in dollars and cents with the decimal point omitted (that is, an integer value in cents). Each record is one entry of a transaction, and a transaction consists of between two and ten entries that share the same sequence number. The entries of each transaction appear consecutively in the input. This part ends with a record whose sequence number is 000.

Output

For a transaction that balances, print nothing.

For a transaction that does not balance, print an exception report in the form

*** Transaction sss is out of balance ***
nnn xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vvvvvvv.vv
nnn xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx vvvvvvv.vv
...
999 Out of Balance                 vvvvvvv.vv

where nnn is an account number, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx is the corresponding account name, and vvvvvvv.vv is the amount. Format each line as: the three-digit account number, one space, the account name left-justified in a 30-character field, one space, and the amount right-justified in a 10-character field. List the entries in the order they were received in the input.

The last line of the report is one you create to make the transaction balance: it uses the special account number 999 (the suspense account) with the name Out of Balance, and its amount offsets the sum of the other entries. Print a blank line between consecutive exception reports.

Examples3

  1. Example 1

    Input
    111Cash 
    121Accounts Receivable
    211Accounts Payable
    241Sales Tax Payable 
    401Sales
    555Office Supplies
    000No such account
    100111    11795
    100121   -11795
    101121      105
    101241       -7 
    101401     -100
    102211   -70000
    102555    40000
    103111   -40000 
    103555    40000
    000000        0
    
    Expected output
    *** Transaction 101 is out of balance ***
    121 Accounts Receivable                  1.05
    241 Sales Tax Payable                   -0.07
    401 Sales                               -1.00
    999 Out of Balance                       0.02
    
    *** Transaction 102 is out of balance ***
    211 Accounts Payable                  -700.00
    555 Office Supplies                    400.00
    999 Out of Balance                     300.00
    
  2. Example 2

    Input
    100Cash
    200Revenue
    000End
    001100     5000
    001200    -5000
    002100    10000
    002200   -10000
    000000        0
    
    Expected output
  3. Example 3

    Input
    100Cash
    200Revenue
    000End
    001100     1000
    001200     -900
    000000        0
    
    Expected output
    *** Transaction 001 is out of balance ***
    100 Cash                                10.00
    200 Revenue                             -9.00
    999 Out of Balance                      -1.00