Infix to Postfix
Medium Accuracy: 48.37% Submissions: 23260 Points: 4

Given an infix expression in the form of a string str. Conver this infix expression to postfix expression.

  • Infix expression: The expression of the form a op b. When an operator is in-between every pair of operands.
  • Postfix expression: The expression of the form a b op. When an operator is followed for every pair of operands.

Input:
The first line of input contains an integer T denoting the number of test cases. The next T lines contains an infix expression.The expression contains all characters and ^,*,/,+,-.

Output:
For each testcase, in a new line, output the infix expression to postfix expression.

Constraints:
1 <= T <= 100
1 <= length of str <= 103

Example:
Input:

2
a+b*(c^d-e)^(f+g*h)-i
A*(B+C)/D

Output:
abcd^e-fgh*+^*+i-
ABC+*D/

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.