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
2019-09-27 08:44:36
I am Chinese who is interested in SPOJ and Poland.
2019-09-16 17:18:54
i am getting SIGABRT averytime
2019-08-03 08:05:56
It's very easy. No recursion or stacks and queue required.
2019-07-14 20:41:13
Just infix to postfix notation easy quite
2019-06-24 09:14:35
the test cases should be updated.. so recursion don't work
2019-06-15 05:50:58
good problem to learn stack and queues.
2019-05-27 16:15:56
wrong answerr need some more test case!
2019-05-22 08:56:34
why do run time errors keep coming in all these online ide's , i am using two arrays of characters .
2019-05-18 09:15:33
Recursive is most correct concept to use.
And make sure that you print solution only after you take all the inputs.


Last edit: 2019-05-18 09:46:24
2019-05-05 11:22:01
Simple just using for and if else blocks
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.