Advertisement blocking software were detected ;( Please add this webpage to whitelist.

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


t [the number of expressions <= 100]
expression [length <= 400]
[other expressions]

Text grouped in [ ] does not appear in the input file.


The expressions in RPN form, one per line.




hide comments
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.

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

In my case it's:

yeahboy: 2015-10-03 12:01:25

how if the input is (a-(b*c)-w-(l-(d-e)*(f+g)+h)^(i*(j-k)/p)) ??
whats is the correct answer?

gj_21: 2015-09-27 09:25:26

finally after 7 submissions made my day :D

catigern: 2015-09-26 18:27:46

Please not that in the question it has been specified, that this a two argument operations inside a bracket, so cases like (a^b + c) don't arise, hence priority of operators doesn't matter

codocalypse: 2015-09-23 19:26:37

Priority of operators is of none importance as the infix expression is completely under brackets !

animi_murali: 2015-09-05 19:43:09

my code is getting runtime error here. It works fine in other IDEs my code id :15070253

Amritendu Mondal: 2015-08-10 11:17:21

I didn't use stack but a tree to store the expression. Good problem , happy to solve this type.

gaurav: 2015-08-08 09:48:11

Are there any boundary conditions we need to check for?
I have not included the operator precedence, however have tested the solution for a range of expressions and it gives the right answer. SPOJ says its wrong. Are there any conditions I need to check for ? Could someone give me example cases?

MishThi: 2015-08-05 11:46:31

Taught me about how stacks function. A great problem for beginners to learn about Stacks. Also, my 49th. :D

Added by:Michał Małafiejski
Time limit:5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel Pentium G860 3GHz)
Languages:All except: NODEJS PERL 6

Problem's scores 1 vote

Concept difficulty
Concept difficulty 20%
Implementation difficulty
Implementation difficulty 14%