题目描述
对于一个不存在括号的表达式进行计算输入描述:
存在多种数据,每组数据一行,表达式不存在空格
输出描述:
输出结果
链接:https://www.nowcoder.com/questionTerminal/7b18aa6b7cc14f8eaae6b8acdebf890b 来源:牛客网 #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; }