给你一个数学表达式,请你求出它的值。
表达式中可能含有以下运算符:”+”、”-“、”*“、”/“、”%”(取余)、”^”(指数)、”(“、”)”,其中优先级为: 括号 > “^” > “*” = “/“ = “%” > “+” = “-“。
// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include <stdio.h>
#include <math.h>
int middle2post_expre(char *post_expre, char *symbol_expre)
{
char str_char;
int symbol_index = 0;
int post_index = 0;
while (scanf_s("%c", &str_char, 1) == 1) {
if (str_char == ' ') {
continue;
} else if (str_char == '$') {
while (symbol_index > 0 && symbol_expre[symbol_index - 1] != ' ') {
post_expre[post_index++] = symbol_expre[--symbol_index];
symbol_expre[symbol_index] = ' ';
}
return 0;
} else if (str_char == '(') {
symbol_expre[symbol_index++] = str_char;
} else if ((str_char >= '0') && (str_char <= '9&