← 返回 ramp 的题目列表Excel Cell Calculation
类型:qbank
Design an Excel-like spreadsheet class supporting set/get operations and dependency-aware formulas. One canonical variant stores sums over cells and ranges; another accepts basic arithmetic formulas between two referenced cells in a fixed 26-by-100 sheet.
Examples
Example 1:
Input: ["Excel", "set", "sum", "set", "get"] [[3, "C"], [1, "A", 2], [3, "C", ["A1", "A1:B2"]], [2, "B", 2], [3, "C"]]
Output: [null, null, 4, null, 6]
Explanation:
The formula in C3 counts A1 once directly and once through the range A1:B2. Updating B2 later changes the formula result from 4 to 6.
Constraints
1 <= height <= 26
A <= width <= Z
1 <= row <= height
A <= column <= width
-100 <= val <= 100
1 <= numbers.length <= 5
Each formula reference is either a single cell or a valid rectangular range.
At most 100 calls will be made to set, get, and sum.
The input will not create circular formula dependencies.
Notes
Alternate canonical variant — basic arithmetic formulas
Initialize a spreadsheet with 26 columns and 100 rows; every cell starts empty.
setCell accepts a literal string, a number, or a formula.
getCell returns the current value of a cell.
A helper such as parseFormula may parse formulas.
Any string beginning with = is a valid formula. Only +, -, *, and / between two cell references are required, such as =B1-B2 or =A1+A2.
Inputs and formulas are valid, so input validation is out of scope.
When either referenced cell changes, every dependent formula value must update accordingly.