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

b1tkn1ght: 2019-04-15 18:00:05

did it without using stack :P

ceesiama: 2019-04-10 03:47:41

I have learnt concepts of stack and queue in c++ because of this problem :)


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 23%
193 6