Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb. Prepared by Ibrahim Mesecan.
Postfix Arithmetic Expressions
In computer science arithmetic expressions can be written in three different styles.
- Infix e.g. (3*6) + (4*7) = 46
- Prefix e.g. + * 3 6 * 4 7 = 46
- Postfix e.g. 3 6 * 4 7 * + = 46
Question: Write a program that is going to read a post fix expression and
then evaluate and show the result on screen.
Note: Use Stacks to solve the problem.
Input specification
A postfix arithmetic expression will be given ending with an equal operator (=).
The expression may contain only numbers and 5 arithmetic operators: '+', '-', '*', '/', and '='.
The numbers will be preceded by '#'. Operators and operands are separated by spaces.
There are at most 10 consecutive numbers in the given expression.
Output specification
Calculate and show one integer: the result of postfix expression.
Sample Input I
#6 #7 #12 #6 / + * #21 - =
|
Sample Input II
#3 #5 #6 * + #13 - #18 #2 / + =
|
Sample Output I
33
|
Sample Output II
29
|
Output Explanation :
The expression given in the first sample can be written as:
6 * (7 + (12 / 6)) - 21 = 33
Для отправки решений необходимо выполнить вход.
|