hdu1170Balloon Comes!

水题我都不想贴题目链接了。

代码

#include <cstdio>
#include <cstring>

char c;
char a[10],b[10];

int main()

{
    int _;
    scanf("%d",&_);
    while(_--)
    {
        getchar();
        scanf("%c%s%s",&c,a,b);
        //printf("%c %s %s\n",c,a,b);
        int t1 = 0;
        for(int i = 0;i < strlen(a);++i)
            t1 = t1 * 10 + a[i] - '0';
        int t2 = 0;
        for(int i = 0;i < strlen(b);++i)
            t2 = t2 * 10 + b[i] - '0';
        //printf("t1 = %d t2 = %d\n",t1,t2);
        if(c == '+')
        {
            printf("%d\n",t1 + t2);
        }
        else if(c == '-')
        {
            printf("%d\n",t1 - t2);
        }
        else if(c == '*')
            printf("%d\n",t1 * t2);
        else if(c == '/')
        {
            if(t1 % t2 == 0)
                printf("%d\n",t1 / t2);
            else
                printf("%.2lf\n",(double)(t1) / (double)(t2));
        }
    }
    return 0;
}

你可能感兴趣的:(ACM,水)