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+^*
|Added by:||Michał Małafiejski|
|Cluster:||Cube (Intel Pentium G860 3GHz)|
|Languages:||All except: NODEJS PERL 6 VB.net|
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
if the input was (a+b^c) , the output should be abc^+ ? true or not? need explanation for several test case
Use stack, and don't forget to format the output the right way. GG :-)
A good algorithm for solving this problem:
Could someone tell me what is wrong in my code http://pastebin.com/fG8x8QTC compile and works well but spoj detects runtime error (SIGSEGV)
Tried solving without using stacks - didnt get the solution even after 2 days.
please do see the priority hehe... giving me one wrong answer :p
STL made code shorter......Excellent problem for beginners.......