-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3484.cpp
More file actions
47 lines (44 loc) · 1.18 KB
/
3484.cpp
File metadata and controls
47 lines (44 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Spreadsheet {
public:
unordered_map<int, unordered_map<int, int>> mp;
Spreadsheet(int rows) {
}
void setCell(string cell, int value) {
int col = cell[0] - 'A';
int row = stoi(cell.substr(1));
mp[col][row] = value;
}
void resetCell(string cell) {
int col = cell[0] - 'A';
int row = stoi(cell.substr(1));
mp[col][row] = 0;
}
bool isCell(string s) {
if (s[0] - 'A' >= 0) return true;
return false;
}
int getValue(string formula) {
formula = formula.substr(1);
int res = 0;
stringstream ss(formula);
string token;
while (getline(ss, token, '+')) {
if (isCell(token)) {
int col = token[0] - 'A';
int row = stoi(token.substr(1));
res += mp[col][row];
}
else {
res += stoi(token);
}
}
return res;
}
};
/**
* Your Spreadsheet object will be instantiated and called as such:
* Spreadsheet* obj = new Spreadsheet(rows);
* obj->setCell(cell,value);
* obj->resetCell(cell);
* int param_3 = obj->getValue(formula);
*/