Reverse Polish notation

Evaluate arithmetic expressions given in the so-called reverse Polish
notation. For instance, the expression
3 + 154
in reverse Polish notation is given as
3 154 +
That is, the two operands are given first, and afterwards comes the
corresponding operator. A more complicated expression like

((3 + 4) * (2 − 8)) + (2 + 5)
is given as

3 4 + 2 8 − * 2 5 + +

Input

Input consists of several arithmetic expressions in reverse Polish
notation, one per line. The operands are natural numbers. The possible
operators, all binary, are ‘+’, ‘-’, and ‘’.

Output

For every expression, print the result of its evaluation.

Problem information

Author: Unknown
Translator: Carlos Molina

Generation: 2026-01-25T11:08:41.547Z

© Jutge.org, 2006–2026.
https://jutge.org
