Design a simple calculator using stack. As shown in the figure, the calculator consists of two stacks, the first one stores integers and the second one 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 , the number of integers in .
The second line contains intergers, it is guaranteed that the absolute value of each integer does not exceed .
The third line contains operators (+
, -
, *
, /
).
You are required to push the intergers given in the second line to in the given order and push the operators given in the third line to 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 .
样例
标准输入 复制文本 |
5 40 5 8 3 2 / * - + |
标准输出 复制文本 |
2 |
标准输入 复制文本 |
5 2 5 8 4 4 * / - + |
标准输出 复制文本 |
ERROR: 5/0 |