Prefix to Postfix Conversion: The program must accept a string S representing a prefix expression as the input. The program must convert the prefix expression to the corresponding postfix expression and print it as the output.
Boundary Condition(s):
3 <= Length of S <= 50
Example Input/Output 1:
Input:
*/+AB-CDE
Output:
AB+CD-/E*
Example Input/Output 2:
Input:
*/+A+BD-EFG
Output:
ABD++EF-/G*
s=input().strip()
stack=[]
operators=set(['+','-','*','/','^'])
s=s[::-1]
for i in s:
if i in operators:
a=stack.pop()
b=stack.pop()
temp=a+b+i
stack.append(temp)
else:
stack.append(i)
print(*stack)