HDU 4493 Tutor(数学啊 )

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4493

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.42100

Source

2013
ACM-ICPC吉林通化全国邀请赛——题目重现

代码如下:

#include <cstdio>
#include <cstring>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        double a, sum, ans;
        sum = 0;
        for(int i = 1; i <= 12; i++)
        {
            scanf("%lf",&a);
            sum += a;
        }
        ans = sum/12.0;
        int tt1 = ans*1000;
        int tt2 = ans*100;
        if(tt1 %10 >= 5)//四舍五入
        {
            tt2+=1;
        }
        if(tt2%100 == 0)//两个零
        {
            printf("$%.0lf\n",ans);
        }
        else if(tt2%10 == 0)//一个零
        {
            printf("$%.1lf\n",ans);
        }
        else
        {
            printf("$%.2lf\n",ans);
        }
    }
    return 0;
}
/*
10
1.555
1.555
1.555
1.555
1.555
1.555
1.555
1.555
1.555
1.555
1.555
1.555
*/
时间: 2025-01-16 07:14:38

HDU 4493 Tutor(数学啊 )的相关文章

hdu 4493 Tutor(简单处理题)

http://acm.hdu.edu.cn/showproblem.php?pid=4493 题意是输入12个数据,让你求平均值,但是要去除尾零,就像100.00只要输出100 其实这题有点不严密,像这组数据 2 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 100.995 输出100,其他可以过的输出100.10以及101都可以 用自己的方法死活不可以过,上网搜了一

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

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("$

hdu 4493 Tutor 水题

Tutor Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4493 Description Lilin was a student of Tonghua Normal University. She is studying at University of Chicago now. Besides studying, she worked as a tutor tea

hdu 4493 Tutor (水 精度)

题意: 思路: #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int fa[150]; int fin(int x) { return fa[x]==x?x:fin(fa[x]); } void unionn(int x,int y) { int fx=fin(x); int fy=fin(y); if(fx

HDU 4493 Tutor (控制精度)

题意:给定12个数,求平均数. 析:这个题就是精度控制问题,如果控制精度,最好的办法就是用整型了. 代码如下: #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include

hdu 4811 Ball(数学)

题目链接:hdu 4811 Ball 题目大意:有三种颜色的球若干,每次向桌子上放一个球,保证是一条序列,每次放球的得分为当前放入序列的球的前面有多少种不同的颜色a,后面的有多少种不同的颜色b,a+b.问说给定球的数量后,最大得分为多少. 解题思路:因为放球顺序是自己定的,所以我们可以尽量早得构造一个序列,使得后面放入球的得分均保持在峰值.那么求峰值就要根据球的数量来决定.我们叫得分为峰值的求为最高得分球,它们有很多个.对于一种颜色来说:0个,表示不能为在最高得分球的左边和右边,换句话来说,就是

hdu 1719 Friend 数学推导

题链:http://acm.hdu.edu.cn/showproblem.php?pid=1719 Friend Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2099    Accepted Submission(s): 1058 Problem Description Friend number are defined recur

hdu 5211 Mutiple 数学

Mutiple Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5211 Description wld有一个序列a[1..n], 对于每个1≤i<n, 他希望你求出一个最小的j(以后用记号F(i)表示),满足i<j≤n, 使aj为ai的倍数(即aj mod ai=0),若不存在这样的j,那么此时令F(i) = 0保证1≤n≤10000,1≤ai≤10000 对于任意