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+^*
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
i thought it was hard one , but i solved it with little effort
I solved it in first attempt without any help using recursion, though my method is very inefficient. I'm so happy, I am gonna try this again with more efficient method.Last edit: 2020-10-29 08:26:32
did using stl stack will effect the time ?Last edit: 2020-10-17 19:09:54
I dont understand of all solution i have gone through, none of them considered associativity in solution. All solutions were based on precedence. why?
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS PERL6 VB.NET|