Expressions in postfix
All submissions for this problem are available.
Faculty at BITS Pilani K.K. Birla Goa Campus has found out that many of their students have problems with the conceptualization of mathematical expressions evaluated in postfix.
You have to help them to develop a program that could evaluate expressions in postfix, therby helpin students to practice.
The program should only handle operations with two operands and one operator, real numbers and the four basic operations: addition, subtraction, multiplication and division. Also the program could only remember two operands.
The input is a file containing many lines for each run with each line having one expression (Each expression's structure is valid). Each line could be up to 100 characters. The program should stop after processing all the expressions. All operations will fit into an 8 bytes number (double).
You are required to show the result of each expression, one result per line. It should have a four digit precision.
123 1254 + 1.254 * 45.87 /
5 4 +
5 4 + 1 + 2 + 12 -
3 2 * 1 - 2 / 3.1415 +
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.