Implement Excel
Asked at Citadel
Reported by the problem's creator, not verified
Build a small spreadsheet. Each cell has a name made of capital letters followed by a row number, such as A1, B12 or AA3, and holds either an integer or a formula. Write the class Spreadsheet with these methods.
set(cell, value)putsvalue, a string, incell, replacing whatever the cell held. A value that does not start with=is an integer, such as"7"or"-3". A value that starts with=is a formula: terms joined by+, where each term is a non-negative integer or the name of a cell, such as"=A1+5","=10+11"or"=B2+B3". The formula's value is the sum of its terms.get(cell)returns the integercellholds right now: a plain integer as it is, a formula as the sum of its terms using the cells' current values.
A cell that was never set holds 0. A formula is live: after a cell it uses changes, get on the formula reflects the new value without the formula being set again. set returns nothing.
Examples
Example 1
Input: init =
[], operations =[["set",["A1","3"]],["set",["B1","=A1+5"]],["get",["B1"]],["set",["A1","10"]],["get",["B1"]],["set",["C1","=10+11"]],["get",["C1"]],["get",["Z9"]]]Output:
[null,null,8,null,15,null,21,0]Explanation:
B1 = A1 + 5 = 8. AfterA1becomes 10,B1reads 15 without being set again.C1 = 10 + 11 = 21, andZ9was never set, so it is 0.