HDU 4493 Tutor (水题)

Tutor

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 47    Accepted Submission(s): 26


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
 

 

 

 

很水,注意去掉后面的0

 

 

 1 /* ***********************************************
 2 Author        :kuangbin
 3 Created Time  :2013/8/24 12:10:26
 4 File Name     :F:\2013ACM练习\比赛练习\2013通化邀请赛\1001.cpp
 5 ************************************************ */
 6 
 7 #include <stdio.h>
 8 #include <string.h>
 9 #include <iostream>
10 #include <algorithm>
11 #include <vector>
12 #include <queue>
13 #include <set>
14 #include <map>
15 #include <string>
16 #include <math.h>
17 #include <stdlib.h>
18 #include <time.h>
19 using namespace std;
20 
21 int main()
22 {
23     //freopen("in.txt","r",stdin);
24     //freopen("out.txt","w",stdout);
25     int T;
26     scanf("%d",&T);
27     while(T--)
28     {
29         double sum = 0;
30         double a;
31         for(int i = 0;i < 12;i++)
32         {
33             scanf("%lf",&a);
34             sum += a;
35         }
36         sum /= 12;
37         char str[1000];
38         sprintf(str,"%.2f",sum);
39         int len = strlen(str);
40         if(str[len-2] == '0' && str[len-1] == '0')
41             str[len-3] = 0;
42         else if(str[len-1] == '0')
43             str[len-1] = 0;
44         printf("$%s\n",str);
45     }
46     return 0;
47 }

 

 

 

 

posted on 2013-08-24 18:30  kuangbin  阅读(997)  评论(1编辑  收藏  举报

导航

JAVASCRIPT: