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+^*
solved by using just stack in one go...!
There is a problem in test cases. My solution is AC in first attempt but later I found out it gives wrong output in those testcases which are without brackets. For example: "a*b+c"
The Great Dijkstra's Shunting Yard Algorithm
I checked out the Shunting yard problem and implemented it. It was such a beautiful algo.
Tbh, I had to search up what RPN was...
well, the test cases don't contain data like a-b*c, whose priority needs to be considered.
easy just use of one stack and one queue.Last edit: 2018-09-21 08:30:31
Last edit: 2018-09-11 12:30:43
Just implement properly !
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS PERL6 VB.NET|