HDU 4493 Tutor(精度处理)

题目

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
#include<stdio.h>
int main()
{
    int t;
    double a,s;
    scanf("%d",&t);
    while(t--)
    {
        s=0;
        for(int i=0;i<12;i++)
        {
            scanf("%lf",&a);
            s+=a;
        }
        //1.注意案例的输出格式
        //2.rounded to the nearest penny

        int ss=s/12.0+0.005;
        printf("$%d",ss);
        int yi,er,shu;
        shu=(s/12.0+0.005)*100;
        yi=shu%100/10;er=shu%10;
        if(yi!=0||er!=0)
        {
            printf(".");
            if(yi!=0&&er==0)
                printf("%d",yi);
            else
                printf("%d%d",yi,er);
        }
        puts("");
    }
    return 0;
}
View Code
一道又一道,好高兴!
原文地址:https://www.cnblogs.com/laiba2004/p/3832457.html