大大幫忙一下:
#include <iostream>
#include <string>
using namespace std;
int main(){
long long a[1000] = {}, i = -1, j = -1, m = 0;
string s = "";
char c, o[1000] = {};
while (!cin.eof()){
c = cin.get();
if (isdigit (c)) s += c;
else{
if (s != "") {sscanf (s.c_str(), "%lld", &a[++i]); s = "";}
if (c != ' '){
if (m == 1) {a[i] *= -1; m = 0;}
if (c == '-' && isdigit (cin.peek())) m = 1;
else if (c == '+' || c == '-' || c == '*' || c == '/' || c == '%')
if (o[j] == '*') {a[i-1] *= a[i]; i--; o[j] = c;}
else if (o[j] == '/') {a[i-1] /= a[i]; i--; o[j] = c;}
else if (o[j] == '%') {a[i-1] %= a[i]; i--; o[j] = c;}
else o[++j] = c;
if (c == '(') o[++j] = c;
if (c == ')')
for (j = j; o[j+1] != '('; j--)
if (o[j] == '+') {a[i-1] += a[i]; i--;}
else if (o[j] == '-') {a[i-1] -= a[i]; i--;}
else if (o[j] == '*') {a[i-1] *= a[i]; i--;}
else if (o[j] == '/') {a[i-1] /= a[i]; i--;}
else if (o[j] == '%') {a[i-1] %= a[i]; i--;}
if (c == '\n'){
for (j = j; j > -1; j--)
if (o[j] == '+') {a[i-1] += a[i]; i--;}
else if (o[j] == '-') {a[i-1] -= a[i]; i--;}
else if (o[j] == '*') {a[i-1] *= a[i]; i--;}
else if (o[j] == '/') {a[i-1] /= a[i]; i--;}
else if (o[j] == '%') {a[i-1] %= a[i]; i--;}
printf ("%d\n", a[0]);
i = j = -1;
}
}
}
}
}