HarveyOA #2
Spreadsheet Formula Evaluator
估计中等可在线判题
Implement SET label expression and GET label. An expression consists only of non-negative integers and cell labels joined by plus signs. A SET that would create a dependency cycle is rejected and the old value is kept; GET returns ERROR for a cell that is unset or whose reference chain cannot be evaluated.
输入格式
Each line contains one command; there are at most 1000 commands and at most 300 distinct labels. A label is an uppercase letter followed by digits; an addition expression has at most 50 terms, literals are ≤10^9, and every evaluable result is guaranteed to fit in a signed 64-bit integer. Referencing an unset cell does not form a cycle; GET returns ERROR in that case.
输出格式
For each command, output OK, ERROR or an integer.
样例 1
输入:
SET A1 7
GET A1
输出:
OK
7
样例 2
输入:
SET A1 B1
GET A1
SET B1 4
GET A1
输出:
OK
ERROR
OK
4
样例 3
输入:
SET A1 B1
SET B1 A1
GET A1
输出:
OK
ERROR
ERROR