Genius mathematician Seongpil
Time limit1sMemory limit128 MB
Evaluate a postfix expression of single digits and the operators +, -, *, / with no spaces.
- Level
Medium4 of 10
- Topics
- Stack, Implementation
- Solved
- No attempts yet
Problem
Seongpil in a parallel world is the leading mathematician of his time, and he invented the digits and operators. Their shapes match the ones in daily use, but the notation differs. In his world an operator follows its operands.
Conversion from ordinary notation to his notation works in two passes. First, add parentheses around the expression according to operator precedence. Then move each parenthesized operator to the right of its closing parenthesis.
For example, groups as under precedence. Moving the inner out gives , and moving gives .
His world has no programming language, so write a program that evaluates his notation in his place.
Input
One expression of length at most is given on one line with no spaces. It contains only single digits from to and the operators , , , .
Every intermediate result is an integer that does not exceed . No division by zero occurs.
The input is always a valid expression.
Output
Print the value of the given expression on the first line.