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

dhuruvapriyan: 2018-12-24 15:46:52

Last edit: 2018-12-24 15:47:23
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
cypher33: 2018-12-19 12:21:17

Got it

surya_55: 2018-12-04 10:43:11

solved by using just stack in one go...!

Ritwik: 2018-12-04 08:18:08

There is a problem in test cases. My solution is AC in first attempt but later I found out it gives wrong output in those testcases which are without brackets. For example: "a*b+c"


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%
169 5