-->
当前位置:首页 > 题库

PROGRAMMING:Inverse Polish expression evaluation

Luz5年前 (2021-05-10)题库527
Inverse Polish representation is a method of describing programs (expressions) by writing operators after operands. For example, we usually use infix representation to describe the formula (1 + 2) \ * (5 + 4), which is changed to inverse Polish representation and then is 12 + 54 + *. Compared with infix notation, the advantage of inverse Polish notation is that it does not need brackets< br/>
Please output the calculation result of the formula input in inverse Polish representation.
###Input format:
Enter 1 formula in one line. Adjacent symbols (operands or operators) are separated by a space.
###Output format:
Output the result of the calculation in one line.
###Restrictions:
2 ≤ the total number of operands in the formula ≤ 100 < br / >
1 ≤ the total number of operators in the formula ≤ 99 < br / >
The operators only include "+", "-", "*", and the operands, the values in the calculation process and the final calculation results are in the range of int.
###Input sample 1:
```in
4 3 + 2 -
```
###Output sample 1:
```out
five
```
###Input sample 2:
```in
1 2 + 3 4 - *
```
###Output sample 2:
```out
-3
```







answer:If there is no answer, please comment