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 1257 最少拦截系统
hdu 1257 最少拦截系统
22 0
|
6月前
|
Java 文件存储
hdu1128 Self Numbers
hdu1128 Self Numbers
23 0
HDU 2669 Romantic
题意:找出最小的非负整数X,使之满足式子X*a + Y*b = 1。