Problem1400--Evaluate Postfix Expression

1400: Evaluate Postfix Expression

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 1
[Submit] [Status] [Web Board] [Creator:]

Description

Write a program to evaluate a postfix expression. You only have to handle four kinds of operators: +, -, x, and /. Format of functions: ElementType EvalPostfix( char *expr ); where expr points to a string that stores the postfix expression. It is guaranteed that there is exactly one space between any two operators or operands. The function EvalPostfix is supposed to return the value of the expression. If it is not a legal postfix expression, EvalPostfix must return a special value Infinity which is defined by the judge program. Sample program of judge: #include #include typedef double ElementType; #define Infinity 1e8 #define Max_Expr 30 /* max size of expression */ ElementType EvalPostfix( char *expr ); int main() { ElementType v; char expr[Max_Expr]; gets(expr); v = EvalPostfix( expr ); if ( v < Infinity ) printf(

Input

where expr points to a string that stores the postfix expression. It is guaranteed that there is exactly one space between any two operators or operands.

Output

where expr points to a string that stores the postfix expression. It is guaranteed that there is exactly one space between any two operators or operands.

Sample Input Copy

11 -2 5.5 * + 23 7 / -

Sample Output Copy

-3.285714

Source/Category