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
2016-04-09 08:18:26 happy
at last....feeling relaxed
2016-03-22 22:39:45
Didn't leave a line after printing output for different test cases... Got stuck for more than an hour... Tragedy of Coding xD
2016-03-09 17:29:33
Got AC in first attemept.. :)
2016-03-07 22:39:58
Wrong answer?! How can I see where?
2016-03-05 17:39:07
it gives me segmentation fault , but when I run it on my pc
it's compiled well and work !
help !?
2016-02-02 11:57:58
Succeed.. But seems like i took long time.. almost 3 hours.. Is this a problem with me only? :-)
2016-01-26 17:57:41
got ac in first attempt.....
easy problem
2016-01-21 14:08:24
hurrah, got AC in first Attempt.
2016-01-20 14:35:49 rahul_verma
feeling relaxed after doing this problem
2016-01-20 13:02:41
For all those who are getting " SIGSEGV " error . Make change in your input. Try changing it to " string "data type or make your array size bigger
like char a[400]. Had the same problem.

Last edit: 2016-01-20 13:04:19
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.