Problem1069--Infix to Postfix

1069: Infix to Postfix

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

Infix expression is defined as "The expression of the form an operator is in-between every pair of operands, for example a(b+c)"
Postfix expression is defined as  "The expression of the form an operator is followed by every pair of operands, for example a b + "

Write a program to convert an infix expression to postfix. The program should take a string representing an infix expression as input and return the corresponding postfix expression as a string.

Here are the only possible operators : +, -, * /, ^ (power of)  and ( )  in the input string, all operant are one digit positive number. 

Example input/output:

Input: "3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3" Output: "3 4 2 * 1 5 - 2 3 ^ ^ / +"

Input: "( 1 + 2 ) * 3 - 4 / 5" Output: "1 2 + 3 * 4 5 / -"

Input: "5 + 4 - 3 * 2 / 1" Output: "5 4 + 3 2 * 1 / -"  





Input

One line of string which is an infix expression, each character is separated by a space. 




Output

one string of postfix, each character is separated by a space 

Sample Input Copy

3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3

Sample Output Copy

3 4 2 * 1 5 - 2 3 ^ ^ / +

Source/Category