Programming contests

DEIK Regionális Programozó Csapatverseny, nyílt kategória, 2022. december 4.

December 4, 2022 10:00 AM – December 4, 2022 3:15 PM

Spreadsheet management

In these dire financial times it is quite difficult for companies to spare money to buy a license for a quality spreadsheet management software, thus we - as senior developers - decided to create a free, however professional application which is able to handle every accounting problem. Unfortunately it seems that we are "not quite as seniors" as we thought, so ultimately we needed to simplify our task to only create a spreadsheet manager which is able to handle the so-called "one column" spreadsheets. Every column of the table will contain the following information:
    VALUE x _ -> changes the value of the cell to x. In this case the second parameter is always the _ character.
    ADD x y -> changes the value of the cell to x+y.
    SUB x y -> changes the value of the cell to x-y.
    MULT x y -> changes the value of the cell to x*y.
The indexing of the cells starts at 0 and increases by one. After the given operation the following type of values can appear:
  • Integers;
  • The character _, which means the "nothing" value;
  • $x, which is a reference to the value of the xth cell. Referencing can happen in both ways, however you may suppose that there are no cyclic references.
Your task is to calculate and print out every final value in a given table.


The input consists of the following lines:
  • The first line contains a positive integer N, which gives the number of cells in the table.
  • The next N number of lines contains three values separated by a single space character: operation par1 par2, where the operation is one of the VALUE, ADD, SUB, MULT choices and par1 and par2 are the parameters (variables) for the given operators as specified above.


The output is N number of lines, each containing the final, calculated integer value to the corresponding table-cell (so the 0th line corresponds to the value of the 0th cell, etc.).


  • 1≤ N ≤ 100;
  • The "number type" parameters (so those which are not of the shape $x or _) has a lower bound of -10000 and an upper bound of 10000;
  • The "reference type" parameters are of the shape $(integer) whose lower bound is $0 (references the value in the 0th cell) and upper bound is $(N-1) (references the value in the last cell). There are no self- or cyclic-references.


  1. 3
  2. VALUE 20 _
  3. ADD $0 100
  4. ADD $1 1
download as text file Output:
  1. 20
  2. 120
  3. 121
download as text file
University of Debrecen; Faculty of Informatics; v. 03/01/2019