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+^*
Browse wikipedia for RPN. You'll get an idea!
The problem statement grossly overstates how complex the input can be. I did not have to account for operator precedence at all, and I could assume every 2 operand sub-expression would have brackets around it!
Do we have to assume that the given algebraic expression will always be correct?
I just wanna leave this here for the next person who does this:
it was a very good problem.i take 2 hours to think it but the solution was very easy.
I used AST and recursive descent. It seems I'm the only one here... Made in python, used tuples for the AST nodes...
Very easy. Got AC in one go. Yeaaa
Don't worry about loops, STL works, complexity can be handles with more indented loops
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS PERL6 VB.NET|