美文网首页
杭电ACM-1170

杭电ACM-1170

作者: 1QzUPm_09F | 来源:发表于2017-01-22 00:16 被阅读0次

    题目:

    1170题

    代码:

    #include<stdio.h>
    int main()
    {
        int n,a,b;
        char c;
        float sum;
        scanf("%d",&n);
        getchar();
        while(n>0)
        {
            c=getchar();
            scanf("%d%d",&a,&b);
            if(c=='+')
            {
                printf("%d\n",a+b);
            }
            else if(c=='-')
            {
                printf("%d\n",a-b);
            }
            else if(c=='*')
            {
                printf("%d\n",a*b);
            }
            else if(c=='/')
            {
                sum=(float)a/b;
                if(a%b!=0)
                    printf("%.2f\n",sum);
                else
                    printf("%d\n",a/b);
            }
            getchar();
            n--;
        }
        return 0;
    }
    

    注意:这题本来很简单,但是!!!一直wrong!!!
    为什么呢???结果就是没仔细读题!!!
    The result should be rounded to 2 decimal places If and only if it is not an integer.
    !!!only if it is not an integer.!!!
    所以在输出除法的时候要加入判断!!!

    相关文章

      网友评论

          本文标题:杭电ACM-1170

          本文链接:https://www.haomeiwen.com/subject/qbbnbttx.html