2013 ACM 通化邀请赛 A. Tutor
A. Tutor
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
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
比较水的一道题,就是求12个数的平均数。但加了一点小小的要求,。就是精确到2位小数,而且如果小数结尾有0,还要去掉
#include<stdio.h>
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
int i;
double sum = 0;
for(i = 0; i < 12; i++)
{
double num;
scanf("%lf", &num);
sum += num;
}
char str[100];
sprintf(str, "%.2lf", sum / 12);
int j;
printf("$");
for(j= 0; str[j]; j++)
{
if(str[j] == '.')
{
if(str[j + 2] == '0')
{
if(str[j + 1] == '0')
break;
else str[j + 2] = 0;
}
}
putchar(str[j]);
}
printf("\n");
}
return 0;
}
2013 ACM 通化邀请赛 A. Tutor的更多相关文章
- 2013 ACM 通化邀请赛D.D-City 并查集
点击打开链接 D.D-City Description Luxer is a really bad guy. He destroys everything he met. One day Luxer ...
- 2013 吉林通化邀请赛 Tutor 有点坑的水题
计算12个数的和的平均数.四舍五入,不能有后导0. 我的做法是,将答案算出后,乘以1000,然后看个位是否大于等于5,判断是否要进位…… #include<iostream> #inclu ...
- 2013 吉林通化邀请赛 Play Game 记忆化搜索
dp[ba][ta][bb][tb]表示a堆牌从下面拿了ba张,从上面拿了ta张.b堆牌从下面拿了bb张,从上面拿了tb张.当前玩家能得到的最大的分数. 扩展方式有4种,ba+1,ta+1,bb+1, ...
- 2013 吉林通化邀请赛 D-City 离线型的并查集
题意:给定n个点和m条边,问你拆掉前i条边后,整个图的连同城市的数量. i从1到m. 思路:计算连通的城市,很容易想到并查集,但是题目里是拆边,所以我们可以反向去做. 存下拆边的信息,从后往前建边. ...
- hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Ot ...
- hduoj 4708 Rotation Lock Puzzle 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4708 Rotation Lock Puzzle Time Limit: 2000/1000 MS (Java/O ...
- hduoj 4715 Difference Between Primes 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4715 Difference Between Primes Time Limit: 2000/1000 MS (J ...
- hduoj 4712 Hamming Distance 2013 ACM/ICPC Asia Regional Online —— Warmup
http://acm.hdu.edu.cn/showproblem.php?pid=4712 Hamming Distance Time Limit: 6000/3000 MS (Java/Other ...
- hduoj 4706 Herding 2013 ACM/ICPC Asia Regional Online —— Warmup
hduoj 4706 Children's Day 2013 ACM/ICPC Asia Regional Online —— Warmup Herding Time Limit: 2000/1000 ...
随机推荐
- httpclient详细介绍
1.HttpClient简介 HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的.最新的.功能丰富的支持 HTTP 协议的客户端编程工具包,并且它支持 ...
- iOS开发笔记-swift实现iOS数据持久化之归档NSKeyedArchiver
IOS数据持久化的方式分为三种: 属性列表 (plist.NSUserDefaults) 归档 (NSKeyedArchiver) 数据库 (SQLite.Core Data.第三方类库等 归档(又名 ...
- libreoffice转office文档为pdf文档
libreoffice5.0 --invisible --convert-to pdf:writer_pdf_Export --outdir "/root/" "bb. ...
- 【架构】生成全局唯一ID的3个思路,来自一个资深架构师的总结
标识(ID / Identifier)是无处不在的,生成标识的主体是人,那么它就是一个命名过程,如果是计算机,那么它就是一个生成过程.如何保证分布式系统下,并行生成标识的唯一与标识的命名空间有着密不可 ...
- mootools里选择器$,$$,$E,$ES等的区别
区别就是 $和$$都是1个参数, $适用于ID,或者ID代表的对象 $$适用于CSS选择器 $E和$ES,有2个参数,第二个参数是可选参数代表(filter,即某个ID范围里的元素) $E('inpu ...
- 【shell】if语句
单分支: #!/bin/bash rate=$(df -h|grep vg_andon-lv_root |awk '{print $5}'| cut -d "%" -f1) #ec ...
- SSH_框架整合2—查询显示
4. 完成功能. (1)com.atguigu.ssh.actions包下新建EmployeeAction.java package com.atguigu.ssh.actions; import j ...
- 编译在arm板上使用的sqlite3的静动态库
采用的是sqlite-autoconf-3080002.tar.gz 解压 tar xvf sqlite-autoconf-3080002.tar.gz 进入 cd sqlite-autoconf-3 ...
- 【MySQL】技巧 之 count(*)、count(1)、count(col)
只看结果的话,Select Count(*) 和 Select Count(1) 两着返回结果是一样的. 假如表沒有主键(Primary key), 那么count(1)比count(*)快,如果有主 ...
- (C#).NET 2.0 ~ 4.0 OS requirements.
.NET 4.0 requires XP SP3, Win2k3 SP2, Vista, 7, or 2008(R2) .NET 3.5 requires XP SP2 or newer. .NET ...