#include<stdio.h> #include<stdlib.h> #include<string.h> #include<math.h> #define MAXN 101 char s[MAXN]; int calac(int L, int R){ int i, p = -1, lv = 0; int m = 0; for (i = L; i <= R; i++){ switch (s[i]){ case '(': lv++; break; case ')': lv--; break; case '+': case '-': if(!lv) p = i; break; case '*': case '/': if(!lv && p == -1) p = i; break; default: m = m * 10 + s[i] - '0'; } } if (p == -1) return s[L] == '(' ? calac(L + 1, R - 1) : m; int a1 = calac(L, p - 1), a2 = calac(p + 1, R); switch (s[p]){ case '+': return a1 + a2; case '-': return a1 - a2; case '*': return a1 * a2; case '/': return a1 / a2; } } int main(){ gets(s); printf("%d ", calac(0, strlen(s) - 1)); system("pause"); return 0; }