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
perl_add_add: 2019-09-27 08:44:36

I am Chinese who is interested in SPOJ and Poland.

gautam97: 2019-09-16 17:18:54

i am getting SIGABRT averytime

neerajamoniya: 2019-08-03 08:05:56

It's very easy. No recursion or stacks and queue required.

scolar_fuad: 2019-07-14 20:41:13

Just infix to postfix notation easy quite

darthcoder3200: 2019-06-24 09:14:35

the test cases should be updated.. so recursion don't work

vurise18: 2019-06-15 05:50:58

good problem to learn stack and queues.

lo0oper: 2019-05-27 16:15:56

wrong answerr need some more test case!

dikshant99: 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 .

veerendrasd_9: 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
backpackman: 2019-05-05 11:22:01

Simple just using for and if else blocks


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

Problem's scores 1 vote

Concept difficulty
Concept difficulty 23%
Implementation difficulty
Implementation difficulty 24%
264 7