Practice Problem - Transform The Expression in Stacks and Queues
Practice Problem - Transform The Expression in Stacks and Queues
Reverse polish notations are easier to parse for computers and you don't
need parentheses to denote precedence of operations.
You can assume that for the test cases below only single letters will be used,
brackets [] will not be used and each expression has only one RPN form (no
expressions like a*b*c)
Input Format
The first line contains t, the number of test cases (less then 100).
Followed by t lines, containing an expression to be translated to RPN form,
where the length of the expression is less then 400.
Output Format
The expressions in RPN form, one per line.
Sample 1:
Input Output
3 abc*+
(a+(b*c)) ab+zx+*
((a+b)*(z+x)) at+bac++cd+^*
((a+t)*((b+(a+c))^(c+d)))
Explanation:
Test case 1: (a+(b*c))