Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
#include <iostream> #include <cstring> #include <string> using namespace std; int main() { double a[205]; char c; int flag = 0; double sum; while (1) { int i; int m; sum = 0; flag = 0;//因为0+0也是有结果的 for (i = 0; i <= 200; i++) a[i] = 0; scanf("%lf", &a[0]); i = 0; while (getchar() != '\n') { flag = 1; scanf("%c %d", &c, &m); switch (c) { case '+': {i++; a[i] = m; break; } case '-': {i++; a[i] = -1.0*m; break; } case '*':a[i] = a[i] * m; break; case '/':a[i] = a[i] * 1.0 / m; break; } } if (flag == 0) break; for (i = 0; i <= 100; i++) sum = sum + a[i]; printf("%.2lf\n", sum); } return 0; }