ONP - Transform the Expression

Transform the algebraic expression with brackets into RPN form (Reverse Polish Notation). Two-argument operators: +, -, *, /, ^ (priority from the lowest to the highest), brackets ( ). Operands: only letters: a, b ... z. Assume that there is only one RPN form (no expressions like a*b*c).

Input

t [the number of expressions <= 100]
expression [length <= 400]
[other expressions]

Text grouped in [ ] does not appear in the input file.

Output

The expressions in RPN form, one per line.

Example

Input:
3
(a+(b*c))
((a+b)*(z+x))
((a+t)*((b+(a+c))^(c+d)))

Output:
abc*+
ab+zx+*
at+bac++cd+^*

Added by:mima
Date:2004-05-01
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL6 VB.NET
Resource:-

hide comments
2020-06-12 06:20:16
no need deep thinking
2020-06-04 15:14:59
can anyone one explain this problem!!
2020-05-26 15:25:01
AC in 1 go! yay!
2020-05-20 22:12:14
ac in one go...
hint use stack
2020-05-12 06:06:28
AC in one go :)
2020-05-07 18:07:04
Use stack.
2020-05-06 14:25:30
so freakin easy! AC in one GO!
2020-04-30 13:38:44
Ac in one go .... so easy
2020-04-20 08:37:40
Used wrong language for submitting, otherwise first time AC and even that in less than 15 min.
2020-03-21 15:25:43
didn't know how to solve using stacks so solved using vector pair ;)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.