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 it using binary expression tree. Class Tree that has pointers to the left and right subtrees and two functions one fills the tree from the input string and the second one reads it in postfix traversal.
Easy just think on paper then code one by one
AC in one go :)
The problem is intresting and good. But the question could have be more clear.
how to submit correct format input ?
my code runs perfectly on my pc. but its showing WA here. What to do?
In this case (a+(b+d)^k) is it abd+k^+ ? . Please correct me if I'm wrong
I am Chinese who is interested in SPOJ and Poland.
i am getting SIGABRT averytime
It's very easy. No recursion or stacks and queue required.
|Cluster:||Cube (Intel G860)|
|Languages:||All except: NODEJS PERL6 VB.NET|