hdu 4493 Tutor

简介:

Tutor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 1981    Accepted Submission(s): 552


Problem Description
Lilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor teaching Chinese to Americans. So, she can earn some money per month. At the end of the year, Lilin wants to know his average monthly money to decide whether continue or not. But she is not good at calculation, so she ask for your help. Please write a program to help Lilin to calculate the average money her earned per month.
 

Input
The first line contain one integer T, means the total number of cases. 
Every case will be twelve lines. Each line will contain the money she earned per month. Each number will be positive and displayed to the penny. No dollar sign will be included.
 

Output
The output will be a single number, the average of money she earned for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign without tail zero. There will be no other spaces or characters in the output.
 

Sample Input
 
 
2 100.00 489.12 12454.12 1234.10 823.05 109.20 5.27 1542.25 839.18 83.99 1295.01 1.75 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00 100.00
 

Sample Output
 
 
$1581.42 $100
 
精度问题
题目要求精确到分,即小数点后2位,故应该看小数点第三位的值,然后四舍五入。

把平均值+上0.005,则能够使第三位满5进一。

#include"stdio.h"
#define N 12
int main()
{
    int n,i;
    double a,s;
    scanf("%d",&n);
    while(n--)
    {
        s=0;
        for(i=0;i<N;i++)
        {
            scanf("%lf",&a);
            s+=a;
        }
        s/=12;
        int m=(s+0.005)*100;          //小数点后第三位四舍五入
        if(m%100==0)
            printf("$%.0f\n",s);
        else if(m%10==0)
            printf("$%.1f\n",s);
        else
            printf("$%.2f\n",s);
    }
    return 0;
}



版权声明:本文博客原创文章。博客,未经同意,不得转载。






本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/4679271.html,如需转载请自行联系原作者


相关文章
|
6月前
|
Java
HDU-1896-Stones
HDU-1896-Stones
27 0
|
人工智能 Java
2021杭电多校5-Arrary-hdu7020
Array Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 965 Accepted Submission(s): 312 Problem Description Given an integer array a[1…n].
178 0
2021杭电多校5-Arrary-hdu7020
|
人工智能 Java
hdu 1712 ACboy needs your help
ACboy这学期有N门课程,他计划花最多M天去学习去学习这些课程,ACboy再第i天学习第j门课程的收益是不同的,求ACboy能获得的最大收益。
137 0
|
机器学习/深度学习 Java 算法