## CCC '04 S3 - Spreadsheet

View as PDF

Points: 10
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
##### Canadian Computing Competition: 2004 Stage 1, Senior #3

A spreadsheet consists of a number of "cells" set in a rectangular grid. Each is addressed with one letter from to (giving the row) and one number from to (giving the column). Thus the upper-left cell of the spreadsheet is , and the lower-right cell is .

Every cell has a value, and this can be specified in one of two ways:

1. as an integer from to
2. as a sum of the values of up to other cells

Cell values may be interdependent (that is, 's sum may depend on which depends on ), but a cell whose value depends on itself, directly or indirectly, is undefined (e.g., depending on depending on ). Also, a cell whose value depends on an undefined cell is itself undefined. You are given the specification for all the cells in the spreadsheet. Compute and output the values of all of the cells.

#### Input Specification

Input will consist of lines, one per spreadsheet row. Each line contains 9 descriptions of a cell, which will be either an integer between and , or a sum of to distinct cell names separated by a + symbol (e.g. A1+B5+D3).

#### Output Specification

Output lines, with numbers per line, giving the value of every cell in the spreadsheet; if the cell is undefined, print an asterisk (*) in place of its value. No cell's final value will exceed .

#### Sample Input

1 2 3 A1+A2+A3 A3+A4 A1+A4+A5 A8+A9 A9 A8
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

#### Sample Output

1 2 3 6 9 16 * * *
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0

• commented on Oct. 16, 2020, 10:11 a.m. edit 16

why does the problem text look so weird (lots of slash slash bracket)

Edit: seems to be just me, dunno why this is happening

• commented on Oct. 16, 2020, 4:13 p.m.

Your math engine is set to "leave as LaTeX" on your profile, so you're seeing the raw LaTeX code instead of the rendered end result.

You can fix this by editing your profile settings and changing the "math engine" option. I would advise the "detect best quality" option.

• commented on Oct. 18, 2020, 12:48 p.m.

Thanks

• commented on March 28, 2020, 2:43 p.m.

If somebody could give me a hint as to why my code does not work, that would be great, thanks!

• commented on Nov. 16, 2019, 5:27 p.m.

Is HashMap a good idea to solve it?

• commented on Jan. 23, 2019, 6:16 a.m.

This comment is hidden due to too much negative feedback. Click here to view it.

• commented on Sept. 29, 2018, 2:41 a.m.

I'm stuck on this problem for so long... I am getting mental issues off of this crap

• commented on Sept. 11, 2017, 9:02 a.m.

The sample input has one line too many of zeros and the output as one line too few of zeros

• commented on Sept. 11, 2017, 11:47 a.m.

The sample I/O has been fixed. Thanks!