Stack
For you humans, math is usually written in infix notations. This means humans usually put the operators between the operand like this:
1 + 1
See how the + is between the operands (the 1 and the other one)?
There is another way to write math, which is using the postfix notation. In the postfix notation, the operator is written after the operands. For example the earlier expression is written like this in postfix:
1 1 +
Here are some more complex examples of infix vs postfix:
Infix
(3 + 9) - (5 + 2)
Postfix
3 9 + 5 2 + -
Infix
((11 - 8) * 3) - 7
Postfix
11 8 - 3 * 7 -
Infix
(9 / 3) - (5 + 12)
Postfix
9 3 / 5 12 + -
Your task is to write a program which evaluate a postfix expression. The operators are +, -, *, and /. The input will always form a valid expression. All the numbers will be integers, treat the / operator as integer division with no remainder.
3 9 + 5 2 + -
5