Home > database >  What went wrong?
What went wrong?

Time:09-17

Expression evaluation

My train of thought: first converted into a postfix expression, again according to the postfix expression method,

C + + 11
Open the O2
Submit code:

A big pile head//import file
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
using namespace std;
Int main ()
{string in x;//in is the input string, a string of x is used for computing, stack Num.//digital stack, which is used to cooperate with string x do arithmetic, stack The op.//symbol stack, but the middle section, and ultimately will pour into doing string x, cin> in; for(int i=0; In [I]!='\ 0'; I++) {if (' 0 '& lt;=[I] in & amp; & In [I] <='9') {//is digital, x +=in [I];//directly to string, the if (! (' 0 '& lt;=a + 1 bonus to [I] in & amp; & In [I + 1] <)='9') {//if there were no number behind,
//then add ', because I use the '. 'segmentation number, behind can according to the'. 'to fill Numbers stack with ten digits, the digits, otherwise, I don't know what are the two number or a number, is wrong, the code behind (naturally) x +='. '. }} else {the if (in [I]=='+' | | in [I]=='-') {//if (! Op. Empty ()) {//if the stack won't have time to back calculation, the if (op. The top ()=='*' | | op. The top ()=='/') {//because of the priority, the multiplication sign must be pressure on the add and subtract Numbers, add and subtract Numbers cannot be pressed on the multiplication sign devide, while (! Op. Empty ()) {//all calculation, empty station, x +=op. Top ();//directly into x, op. Pop ();//useless, throw trash can, x +='. './/I'm still in 'to separate,}//after all this, will to push at the back,}} op. Push in [I]);//push this symbol,} else {op. Push in [I]);//, highest priority, don't have to and add and subtract Numbers that determine priorities,}}} while (! Op. Empty ()) {//to empty stack, x +=op. Top (); Op. Pop (); X +='; }
//cout} this code myself to a data can be passed, but it can only have a test point, why?

CodePudding user response:

Used c + + 11
  • Related