## DWITE '07 R4 #5 - It all adds up

View as PDF

Points: 7
Time limit: 1.0s
Memory limit: 64M

Problem type
##### DWITE Online Computer Programming Contest, January 2008, Problem 5

The business world runs on spreadsheets, and Tony needs one small enough to run on a toaster – meaning it will have just 5 by 5 cells, and only basic operations: +, -, *

The input will contain lines – first lines are column : . Second 5 lines are column : . Etc. Each line will hold either an integer, or an expression in the form =CELL (operator CELL)*, where (operator CELL) part could be repeated up to 5 times. All input values will be integers, . No expression will exceed the value of . There will be no infinite loops in equations. Refer to the sample input for examples.

The output will contain lines – a solved spreadsheet, where each line holds an integer value. The calculations are primitive, the order of calculations are from left to right. That is, an expression =2 + 2 * 3 will equate to , not .

#### Sample Input

0
1
=A2
=A2 + A3
=A4 + A3
=A2 * A4 + A5
8
=B1 * A4 + 3
=B1 * 4 + 1
=5 + 5 + 5 * 2 + 4
55
89
144
233
377
=D3 - D2
=D4 - D3
=D5 - D4
2584
4181
6765
10946
17711
28657
46368

#### Sample Output

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368

Problem Resource: DWITE