输入
复制
6/2+3+3*4
输出
复制
18
#include<iostream>
using namespace std;
int main() {
double val[1010];
while (~scanf("%lf", &val[0])) {
char op;
int ai = 0;
double nex;
while (~scanf("%c", &op) && op != '\n') {
scanf("%lf", &nex);
switch (op) {
case '+':val[++ai] = nex; break;
case '-':val[++ai] = -nex; break;
case '*':val[ai] *= nex; break;
case '/':val[ai] /= nex; break;
}
}
double res = 0;
for (int i = 0; i <= ai; ++i)
res += val[i];
cout << res << endl;
}
return 0;
}