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+^*

hide comments
chandansirola: 2016-04-18 16:52:15

done (y)

Last edit: 2016-04-18 16:55:21
jkaszycki: 2016-04-16 21:18:21

Reverse Polish Notation is such:
2 2 +
Not
2 + 2
Mind the gap...

happy: 2016-04-09 08:18:26

at last....feeling relaxed

nischaymalhan: 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

pica_power: 2016-03-09 17:29:33

Got AC in first attemept.. :)

last_mohican: 2016-03-07 22:39:58

Wrong answer?! How can I see where?

geekahmed: 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 !?

shyam55555: 2016-02-02 11:57:58

Succeed.. But seems like i took long time.. almost 3 hours.. Is this a problem with me only? :-)

imshubhamk: 2016-01-26 17:57:41

got ac in first attempt.....
easy problem

rajanbitp: 2016-01-21 14:08:24

hurrah, got AC in first Attempt.


Added by:Michał Małafiejski
Date:2004-05-01
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: NODEJS PERL 6 VB.net
Resource:-

Problem's scores 1 vote

Concept difficulty
Concept difficulty 21%
Implementation difficulty
Implementation difficulty 17%
45 2