• 2013 吉林通化邀请赛 Tutor 有点坑的水题


    计算12个数的和的平均数。四舍五入,不能有后导0。

    我的做法是,将答案算出后,乘以1000,然后看个位是否大于等于5,判断是否要进位……



    #include<iostream>
    #include<cstdio>
    #include<string.h>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    #define eps 1e-2
    int main()
    {
        int cas;
        scanf("%d",&cas);
        while(cas--)
        {
            double sum=0;
            double a;
            int maxn=0;
            for(int i=1;i<=12;i++)
            {
                int tot=0;
                scanf("%lf",&a);
                sum+=a;
            }
            sum=sum/12;
            int t=sum*1000;
            if(t%10>=5) t=t/10+1;
            else t=t/10;
            if(t%100==0)
            {
                printf("$%.0lf
    ",sum);
            }
            else if(t%10==0)
            {
                printf("$%.1lf
    ",sum);
            }
            else printf("$%.2lf
    ",sum);
        }
    }


  • 相关阅读:
    模块的搜索路径
    循环导入问题
    模块的四种形式
    匿名函数
    面向过程编程
    内置函数
    名称空间和作用域
    函数嵌套
    函数对象
    可变长参数
  • 原文地址:https://www.cnblogs.com/riskyer/p/3279894.html
Copyright © 2020-2023  润新知