Given this Wednesday, there are no regular classes in the afternoon. In addition, the suffix results are quite simple. Let's write this first. I have already converted the expression. Now I only need to perform a group of numbers, addition, subtraction, multiplication, division, and so on. (To be honest, it's a bit lazy. Recently, the PM2.5 in Changchun is a little high, I am not interested in ACM at all.) intchange (char * a) {stackint
Given this Wednesday, there are no regular classes in the afternoon. In addition, the suffix results are quite simple. Let's write this first. I have already converted the expression. Now I only need to perform a group of numbers, addition, subtraction, multiplication, division, and so on. (To be honest, it's a bit lazy. Recently, the PM2.5 in Changchun is a little high, I am not interested in ACM at all.) int change (char * a) {stack int
Given this Wednesday, there are no regular classes in the afternoon. In addition, the suffix results are quite simple. Let's write this first.
I have already converted the expression. Now I only need to perform a group of numbers, addition, subtraction, multiplication, division, and so on. (To be honest, it's a bit lazy. Recently, the PM2.5 in Changchun is a little high, I am not interested in ACM at all)
Int change (char *)
{
Stack T;
Int I = 0;
While (a [I]! = '\ 0 ')
{
If (a [I]> = '0' & a [I] <= '9') // Press
{
T. push (int) a [I ++]-'0 ');
}
Else
{
Int num1, num2;
Num1 = t. top (); t. pop ();
Num2 = t. top (); t. pop ();
Switch (a [I ++]) // if there is an operator, extract the number first, and then compress the result.
{
Case '+': num1 + = num2; t. push (num1); break;
Case '-': num2-= num1; t. push (num2); break;
Case '*': num1 * = num2; t. push (num1); break;
Case '/': num2/= num1; t. push (num2); break;
}
}
}
Return t. top (); // finally, the last number left in the stack is the result you want.
}
Because I want to see something behind the data structure, I am anxious to end it. These two functions can only be used for single-digit operations without inserting blank lines in the suffix expression to differentiate numbers, so keep it for me and write it again .. (Sleepy)
Over