DWITE '07 R4 #5 - It all adds up

View as PDF

Submit solution

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
DWITE Online Computer Programming Contest, January 2008, Problem 5

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 25 lines – first 5 lines are column A: A1, A2, A3, A4, A5. Second 5 lines are column B: B1, B2, B3, B4, B5. 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, 0 \le n \le 99\,999. No expression will exceed the value of 99\,999. There will be no infinite loops in equations. Refer to the sample input for examples.

The output will contain 25 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 12, not 8.

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

Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


Comments

There are no comments at the moment.