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
iamareebjamal: 2016-01-13 11:47:36

Runs perfectly on ideone.com
SIGSEGV here <snip>

Last edit: 2023-02-09 23:13:58
cherag_0001: 2016-01-04 08:32:29

whooo hoo !! 2nd try ..// in the first try just an "endl" missing :P

skrishna99: 2015-12-31 10:41:16

I got RTE(NZec) I tried all known options to me , finally identified that I have not pushed "-" to stack . Pretty easy problem using stacks.
My first one in stack .

ashu14: 2015-12-27 15:51:29

@yeahboy this type is not allowed.. As it can have multiple rpn forms possible!

motasem mohammad: 2015-12-25 14:10:18

taught me how to use stack function , a good problem

aakash_s: 2015-12-17 18:36:07

Take care of the case a+b without any brackets ...caused me several wrong answers

Last edit: 2015-12-28 11:04:45
Timmy Jose: 2015-12-13 21:25:34

Nice question - excellent motivation to revise old college stuff! :-)

MAYANK NARULA: 2015-12-09 07:05:06

@ yeahboy ... My answer for that is abc*-w-lde-fg+*-h+ijk-*p/^-

But i am getting WRONG ANSWERS in SPOJ...!!

Now i got it AC ... Can't resist making output format mistakes !!

Last edit: 2015-12-09 07:10:57
Mayur Aggarwal: 2015-10-21 14:25:15

My code is giving correct answer on ideone but couldn't able to nail down the issue/bug for which SPOJ is giving wrong answer. few checks are given below please advise if any see any issue:
All variables declared with array size 401,
if(T<=100 && T >=1) //test condition
if(strlen(str) <=400 && strlen(str) >=1) // input check
logic seems to be correct.. As per SPOJ guidelines I can't post source code here. Please post more test cases here so that I can validate my code.
Any help is appreciated.
Thnaks!!

Michael: 2015-10-12 21:04:55

In my case it's:
abc*wlde-fg+h+*-ijk-p/*^---


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