intgetValue(string formula){ int res_value = 0; string formula_s = formula.substr(1); std::stringstream ss(formula_s); vector<string> values; string token; while (std::getline(ss, token, '+')) { values.push_back(token); } int int_value; for (string value : values) { try { int_value = std::stoi(value); } catch (std::invalid_argument) { auto [row, column] = get_row_and_column(value); int_value = sheet[row][column]; } res_value += int_value; } return res_value; } };
/** * 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); */ intmain(){ // ["Spreadsheet","getValue"] // [[458],["=O126+10272"]]
Spreadsheet *obj = newSpreadsheet(458); int result = obj->getValue("=O126+10272"); printf("result is %d\n", result); delete obj;