杭电ACM-1170

题目:

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.!!!
所以在输出除法的时候要加入判断!!!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容