Postfix Notation

View as PDF

Submit solution

Points: 7
Time limit: 1.4s
Memory limit: 64M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

We are familiar with infix notation for representing expressions, where the operator is placed infix between the operands, as in 5 * 5. Given an expression in postfix notation, such as 5 5 *, evaluate the expression and print it to standard output, rounded to one decimal place.

Valid operands are * (multiplication), / (division), + (addition), - (subtraction), % (mod), and ^ (exponentiation).

Input Format

A valid postfix expression. The input will have no more than 50 characters, and the value of each number in the input and each intermediate result will be less than or equal to 1000.

Output Format

The result of the evaluation. The answer will be considered correct if its absolute or relative error does not exceed 10^{-1}.

Sample Input

5 5 +

Sample Output

10.0

Sample Input

5 5 + 6 * 8 -

Sample Output

52.0

Comments


  • 0
    anasschoukri2  commented on Aug. 25, 2017, 11:23 a.m.

    input

    what is the type of numbers in input ??


    • -1
      Pleedoh  commented on Aug. 25, 2017, 12:41 p.m.

      Just use floating point


  • 61
    quantum  commented on Sept. 13, 2014, 8:59 p.m. edited

    Reverse Polish Sausage.