#include<bits/stdc++.h>
using namespace std;
string sy = "0123456789+-*/=";
int main(){
string s;
cin >> s;
int res = 0;
queue<string> q;
int num = 0;
for (int i = 0; i < s.size(); i ++){
if (sy.find(s[i]) == -1){
cout << "ERROR" << endl;
return 0;
}
if (s[i] >= '0' && s[i] <= '9'){
num = num * 10 + s[i] - '0';
}else{
q.push(to_string(num));
num = 0;
string yun = "";
yun += s[i];
q.push(yun);
}
}
res = stoi(q.front());
q.pop();
while(!q.empty()){
string yun = q.front();
q.pop();
if (q.empty()) break;
num = stoi(q.front());
q.pop();
if (q.empty()) break;
if (yun == "+") res += num;
else if (yun == "-") res -= num;
else if (yun == "*") res *= num;
else if (yun == "/"){
if (num == 0){
cout << "ERROR" << endl;
return 0;
}
res /= num;
}
}
cout << res << endl;
return 0;
}
05-27
1101
1101

被折叠的 条评论
为什么被折叠?



