打倒诶嘿抢榜一 • 5个月前
using namespace std; stackdata; stackop;
int check(char c) {
int a = 0;
if (c == '+')
a = 1;
if (c == '*')
a = 2;
return a;
}
void deal() {
char c = op.top();
op.pop();
int a, b;
a = data.top();
data.pop();
b = data.top();
data.pop();
if (c == '+')
data.push(a + b);
if (c == '*') {
int d = b * a;
data.push(d % 10000);
}
}
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
int d = 0;
if (s[i] >= '0' && s[i] <= '9') {
while (s[i] >= '0' && s[i] <= '9') {
d = d * 10 + (s[i] - '0');
i++;
}
data.push(d);
i--;
} else {
while (!op.empty() && check(op.top()) >= check(s[i]))
deal();
op.push(s[i]);
}
}
//cout << "$";
while (!op.empty()) {
deal();
}
cout << data.top() % 10000;
return 0;
}
评论:
请先登录,才能进行评论