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.
Input: 3 (a+(b*c)) ((a+b)*(z+x)) ((a+t)*((b+(a+c))^(c+d))) Output: abc*+ ab+zx+* at+bac++cd+^*
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:
In my case it's:
how if the input is (a-(b*c)-w-(l-(d-e)*(f+g)+h)^(i*(j-k)/p)) ??
finally after 7 submissions made my day :D
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
Priority of operators is of none importance as the infix expression is completely under brackets !
my code is getting runtime error here. It works fine in other IDEs my code id :15070253
I didn't use stack but a tree to store the expression. Good problem , happy to solve this type.
Are there any boundary conditions we need to check for?
Taught me about how stacks function. A great problem for beginners to learn about Stacks. Also, my 49th. :D
|Added by:||Michał Małafiejski|
|Cluster:||Cube (Intel Pentium G860 3GHz)|
|Languages:||All except: NODEJS PERL 6 VB.net|