Design a simple calculator using stack. As shown in the figure, the calculator consists of two stacks, the first one s_1 stores integers and the second one s_2 stores operators. There is an = key at the bottom of the calculator. Each time you press this key, the calculator performs the following operations:
When both stacks are empty, the calculation ends and the final result is displayed on the screen.
输入
The first line contains a integer n \ (1 \leq n \leq 10^3), the number of integers in s_1.
The second line contains n intergers, it is guaranteed that the absolute value of each integer does not exceed 100.
The third line contains n-1 operators (+
, -
, *
, /
).
You are required to push the intergers given in the second line to s_1 in the given order and push the operators given in the third line to s_2 in the given order.
输出
If you find the divisor is zero when doing division, output ERROR: X/0
and terminate your program immediately, where X
is the dividend at that time.
Otherwise, output the final result. It is guaranteed that the absolute value of the answer does not exceed 10^9.
样例
标准输入 复制文本 |
5 40 5 8 3 2 / * - + |
标准输出 复制文本 |
2 |
标准输入 复制文本 |
5 2 5 8 4 4 * / - + |
标准输出 复制文本 |
ERROR: 5/0 |