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

charlles: 2019-04-09 16:14:58

there is an recursive solution to it?

stones: 2019-03-25 19:17:28

AC in One go :P

mohanteja1: 2019-02-16 12:37:43

solved this with recursion

lnediak: 2019-01-27 21:01:15

lol I did rly stupid i didn't use stack i created dumb token class and separate on operator but it works anyways i think maybe logn times slower than stack

traitorakali: 2019-01-08 07:16:03

Why I keep geting runtime error (NZEC) ?

karankeswani99: 2019-01-07 18:58:28

Just use stack

rajulrs13: 2018-12-30 22:10:19

got me stuck for an hour because I took expression length to be 100.. : (

sehgal_divij: 2018-12-23 13:12:22

Why would my code take 16M Memory to execute?
I used C++ and STL constructs. Is that the reason it took too long to execute?
Would it have been better if I had used just the basic char arrays to perform operations?

Last edit: 2018-12-23 13:13:06

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