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+^*
0.00 sec in ASM
Solved without stack data structure !!!
You can try the Shunting Yard approach, or even go for RD parsing using a LL(k) grammar.
no need to consider the special cases i.e. when parenthesis are not there.
Since expression is given in fully parenthesised format (as in examples) there is no need to take care of priorities of operators...
A stack is not required in this problem. However, it is easier to use a stack!Last edit: 2018-01-16 12:20:45
AC in one go (0.08s with Java)Last edit: 2018-01-06 04:27:44
Stacks are required always
AC using assembly
@ajay_raj_: You don't need a stack. I've solved mine using regular expressions and recursion.
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS PERL6 VB.NET|