Design a basic Excel spreadsheet that supports storing integer values, retrieving cell values, and assigning sum formulas to cells.
Rows are numbered starting from 1, and columns are labeled from 'A' through the configured final column. Every cell initially contains 0.
Excel
Excel(int H, char W)
H: The number of rows in the spreadsheet.W: The final column label. The spreadsheet contains every column from 'A' through W.Initialize an H-row spreadsheet whose cells all contain 0.
void Set(int row, char column, int val)
row: The row number of the cell.column: The column label of the cell.val: The new integer value.Assign val to the specified cell. If that cell previously contained a sum formula, the formula is removed and replaced by the given value.
int Get(int row, char column)
row: The row number of the requested cell.column: The column label of the requested cell.Return the current value of the specified cell. If the cell contains a formula, return its value after applying all relevant cell updates.
int Sum(int row, char column, List<String> numbers)
row: The row number of the formula cell.column: The column label of the formula cell.numbers: Cell references and rectangular cell ranges whose values must be added.Store a sum formula in the specified cell and return its current result. This formula replaces any value or formula previously stored in that cell.
The formula remains active until the cell is overwritten by another call to Set or Sum. Its value must update when any directly or indirectly referenced cell changes.
"ColRow". For example, "D4" represents column D, row 4."TopLeft:BottomRight". For example, "B2:D5" contains every cell from B2 through D5, inclusive.Each occurrence of a cell contributes separately to the result. Therefore, cells repeated directly, through overlapping ranges, or through duplicate entries are counted multiple times.
1 ≤ H ≤ 26'A' ≤ W ≤ 'Z'1 ≤ row ≤ H'A' ≤ column ≤ W-100 ≤ val ≤ 1001 ≤ numbers.size() ≤ 100numbers is a valid cell reference or rectangular range within the spreadsheet.1,000 calls are made to Set, Get, and Sum.Excel instance is independent and begins with all cells set to 0.Excel(H = 4, W = "D")
Creates a spreadsheet with four rows and columns A through D. Every cell starts at 0.
Set(row = 2, column = "B", val = 5)
Output: No return value. Cell B2 now contains 5.
Sum(row = 4, column = "D", numbers = ["B2", "A1:B2"])
Output: 10
Cell B2 is counted once by "B2" and once inside "A1:B2".
Set(row = 1, column = "A", val = 3)
Output: No return value. The formula stored in D4 automatically changes from 10 to 13.
Get(row = 4, column = "D")
Output: 13
Excel(H = 3, W = "C")
Creates a three-row spreadsheet with columns A, B, and C.
Set(row = 1, column = "A", val = 4)
Output: No return value.
Sum(row = 3, column = "C", numbers = ["A1:B2"])
Output: 4
Set(row = 3, column = "C", val = 7)
Output: No return value. The formula in C3 is removed.
Set(row = 2, column = "B", val = 9)
Output: No return value. Since the formula in C3 was overwritten, changing B2 does not change C3.
Get(row = 3, column = "C")
Output: 7