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 ...
随机推荐
- 设置页面不缓存 no-cache
html中设置方法 <head> <META HTTP-EQUIV="Pragma" CONTENT="no-cache"> <M ...
- 使用 jQuery UI Widget Factory 编写有状态的插件(Stateful Plugins)
使用 jQuery UI Widget Factory 编写有状态的插件(Stateful Plugins) Note 这一章节的内容是基于 Scott Gonzalez 一篇博客 Building ...
- SQLSERVER 脚本转MYSQL 脚本的方法总结
1.MYSQL(版本为5.6)中SQL脚本必须以分号(;)结尾,这点比SQLSERVER要严谨:关键字与函数名称全部大写:数据库名称.表名称.字段名称全部小写. 2.所有关键字都要加上``,比如 St ...
- final,static
如果输入参数在方法体执行过程中,强制不能被修改,那么参数类型前加final比较安全. final修饰的函数会被编译器优化,优化意味着编译器可能将该方法用内联(inline)方式载入.final修饰变量 ...
- C#文本文件(.txt)读写
目录 前言 读取txt文件 写入txt文件 前言 计算机在最初只支持ASCII编码,但是后来为了支持其他语言中的字符(比如汉字)以及一些特殊字符(比如€),就引入了Unicode字符集.基于Unico ...
- 如何增加swap 大小
第一步:(这里增加2G) [root@kmdbrac1 /]# mkdir swap #创建一个文件夹,存放交换空间文件 [root@kmdbrac1 /]# cd swap # ...
- (转载)CentOS6下 源代码方式安装openERP7.0
CentOS6下 源代码方式安装openERP7.0 安装背景 :CPU32 bit,CentOS 6.4版本,openERP7.0,linux shell为bash,PostgreSQL9.2 1. ...
- SQLServer数据库字典维护方法
启用SQLServer启用管理器,以2008为例 1.设置表信息描述 选中要设置的表,右键点击“属性” . 选择扩展属性 填写要求: 名称:MS_Description 值: 模块名称-表名称 修改语 ...
- Ajax方法执行跳转或者加载操作系统报出这样错误Sys.WebForms.PageRequestManagerParserErrorException:如何让解决
当你在代码中使用Response.Redirect(); 或者Response.Write();难免会遇到Sys.WebForms.PageRequestManagerParserErrorExce ...
- sql server 2012 如何收缩事务日志
sql2008不再支持 BACKUP LOG 数据库名 WITH NO_LOG 语句 BACKUP Log zxta with no_log 截断事务日志 sql2008 提示错误如下 BACKU ...