阅读背景:

题目1019:简单计算器_Aden的专栏

来源:互联网 

#include<cstdio>  
using namespace std;
 
int main()
{
    char ch;
    int i, j, temp;
    double a[200];
    while (scanf("%d", &temp) != EOF&&temp!=0)
    {
        i = 1;
        a[0] = 0;
        a[1] = temp;
        scanf("%c", &ch);
        while (scanf("%c", &ch) != EOF && ch != '\n')
        {
            char tmp = ch;
            scanf("%c", &ch);
            scanf("%d", &temp);
            if (tmp == '-')a[++i] = -temp;
            else if (tmp == '+')a[++i] = temp;
            else if (tmp == '*')a[i] *= temp;
            else if (tmp == '/')a[i] /= temp;
            scanf("%c", &ch);
            if (ch == '\n') break;
        }
        for (j = 1; j <= i; ++j)
            a[0] += a[j];
        printf("%.2f\n", a[0]);
    }
    return 0;
}
/**************************************************************
    Problem: 1019
    User: cust123
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1020 kb
****************************************************************/#include<cstdio>  
using namespace std;
 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: