Reverse Polish notation P52023


Statement
 

pdf   zip

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

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

34+28*25++3 \enspace 4 \enspace + \enspace 2 \enspace 8 \enspace - \enspace * \enspace 2 \enspace 5 \enspace + \enspace +

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.

Public test cases
  • Input

    3 154 +
    3 4 + 2 8 - * 2 5 + +
    99
    

    Output

    157
    -35
    99
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Translator
    Carlos Molina
    Original language
    Catalan
    Other languages
    Catalan
    Official solutions
    C++ Python
    User solutions
    C++ Haskell Python