HDU 4493 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
 

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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值