Starting from:
$30

$24

Data Structures Homework #1 Solution

Description

Please check the format of the postfix expression that is correct or not, and transform it into the infix and prefix expression and evaluate.

Please note that we specify the prefix expression should be transformed by the infix expression without redundant parenthesis.

Time Limit: 1 second

Input

The input is a postfix expression without any space character, which is a line of string.

Each operand is a digit (0 - 9), and the set of operators are : +-*/

(plus, minus, multiply, divide).

The postfix expression includes only operands and operators mentioned above.

The length of input postfix expression is between 1 and 1000 characters.

Output

There would be 2 cases for the output.

If the format of the postfix expression is wrong, output False.
NO endl behind False.
Otherwise, output three lines:
First line: the corresponding infix expression
Second line: the corresponding prefix expression
Please note that we specify the prefix expression should be transformed by the infix expression without redundant parenthesis, not by the postfix.
Don't directly transform the postfix into prefix for the prefix answer.
Third line: the evaluated value.
NO endl behind value.
The output evaluated value will be a Positive Integer (32 bit signed) or 0.
The infix expression should contain only the necessary parenthesis and should not contain redundant parenthesis.

Please note that we specify the prefix expression should be transformed by the infix expression without redundant parenthesis.

Don't directly transform the postfix into prefix for the answer.

Sample Input  

123+

12+3*231/+*

Sample Output  

False

(1+2)*3*(2+3/1)

**+123+2/31

45

More products