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
2018-01-06 04:27:05
AC in one go (0.08s with Java)

Last edit: 2018-01-06 04:27:44
2018-01-05 06:51:25
Stacks are required always
2018-01-05 06:49:19
AC using assembly
2017-12-28 20:14:11
@ajay_raj_: You don't need a stack. I've solved mine using regular expressions and recursion.
2017-12-13 19:42:08
I'm The best! LOL
2017-11-20 15:32:17
Stack is required
2017-10-28 17:52:25
What does AC mean ? :D
2017-10-14 09:13:53
wrong answer !?
guess what?
2017-10-08 05:50:31
Test cases are very weak!!
first got AC with right logic then i made wrong changes and also got AC.
2017-09-15 18:41:24
AC in one go !!!!!
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.