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;
}

hdu 4493 Tutor

时间: 2024-10-19 10:11:04

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(精度处理)

题目 #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(数学啊 )

题目链接: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

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 4493

题目链接 注意四舍五入,保留到小数点后两位(如果存在的话). 附上代码: 1 /************************************************************************* 2 > File Name: 4493.cpp 3 > Author: Stomach_ache 4 > Mail: [email protected] 5 > Created Time: 2014年05月19日 星期一 22时39分19秒 6 > P

HDU 6203 ping ping ping [LCA,贪心,DFS序,BIT(树状数组)]

题目链接:[http://acm.hdu.edu.cn/showproblem.php?pid=6203] 题意 :给出一棵树,如果(a,b)路径上有坏点,那么(a,b)之间不联通,给出一些不联通的点对,然后判断最少有多少个坏点. 题解 :求每个点对的LCA,然后根据LCA的深度排序.从LCA最深的点对开始,如果a或者b点已经有点被标记了,那么continue,否者标记(a,b)LCA的子树每个顶点加1. #include<Bits/stdc++.h> using namespace std;

HDU 5542 The Battle of Chibi dp+树状数组

题目:http://acm.hdu.edu.cn/showproblem.php?pid=5542 题意:给你n个数,求其中上升子序列长度为m的个数 可以考虑用dp[i][j]表示以a[i]结尾的长度为j的上升子序列有多少 裸的dp是o(n2m) 所以需要优化 我们可以发现dp的第3维是找比它小的数,那么就可以用树状数组来找 这样就可以降低复杂度 #include<iostream> #include<cstdio> #include<cstring> #include