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
2011-12-29 19:41:25 Klaus
I find it unbelivable that the most get it done in 0.0s . I thought my 0.14 s are not that bad. I do not think there is a general difference in the algorithm, but perhaps in the way how things are done (something like coding style)?

Last edit: 2012-01-06 12:08:16
2011-10-12 15:37:41 Ravi Kumar
hey i have solved this problem in my netbeans and working fine for the sample inputs but when i am submitting by pasting the code its showing compiler error. can any one help me is there any convention for class name or what exactly the problem is?
2011-06-11 17:39:28 Santiago Palacio
@viveck verma: no, all the expresions are binary, and between brackets.

@Saivivekh Swaminathan: C# is slower than other languajes like C, or C++, that's why they run faster.

Last edit: 2011-06-11 17:40:28
2011-02-17 05:31:23 Manoj Ransing
Can I expect the expressions like a+b*c? (without () brackets)
2009-08-30 23:12:53 Gabriel Peixoto
I forgot to empty my operand stack after reading the expression and got AC!

Input: a+b
My program answer: ab (without the +)
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.