天天看點

HDU 4493 Tutor (基礎題)Tutor

Tutor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)

Total Submission(s): 1038    Accepted Submission(s): 297

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
        

Source 2013 ACM-ICPC吉林通化全國邀請賽——題目重制  

Recommend liuyiding

題意:

給出12個數,求平均值

注意:

1.輸出前有“$”符号

2.題意中未給出的條件:對于一個小數最多取兩位小數,再去掉小數後面的字尾0或再去掉小數點

/*************************************************************************
	> File Name: JJJ.cpp
	> Author: BSlin
	> Mail:  
	> Created Time: 2013年10月06日 星期日 12時38分44秒
 ************************************************************************/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#define MP make_pair
#define INF (1<<30)
#define PI acos(-1.0)
#define esp 1e-8
const int dx[4]={0,0,0,0};
using namespace std;
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#if defined (_WIN32) || defined (__WIN32) || defined (WIN32) || defined (__WIN32__)
#define LL __int64
#define LLS "%" "I" "6" "4" "d"
#else
#define LL long long
#define LLS "%" "l" "l" "d"
#endif



int main(int argc, char** argv) {
    //read;
    int t,sum_int;
    double x,sum;
    scanf("%d",&t);
    while(t--) {
        sum = 0;
        for(int i=1; i<=12; i++) {
            scanf("%lf",&x);
            sum += x;
        }
        sum /= 12;
        //sum = 12.014;
        //printf("$%f\n",sum);
        sum_int = (int)((sum + 0.005) * 100);
        int a,b;
        b = sum_int % 10;
        a = sum_int / 10 % 10;
        if(b == 0 && a == 0) {
            printf("$%d\n",(int)sum);
        }
        else if(b == 0) {
            printf("$%.1f\n",sum);
        }
        else {
            printf("$%.2f\n",sum);
        }
        //printf("%d\n",sum_int);
        //printf("%d %d \n",a,b);
    }
    return 0;
}