HDU-4493 Tutor (模拟)
2016-04-30 14:26
323 查看
Tutor
http://acm.hdu.edu.cn/showproblem.php?pid=4493Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
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
题目大意:求12个数的平均数,没有末尾0
其实早就发现了0.5的舍入各个编译器有差别,但是一般加上EPS就能过了,但是本题在重现时貌似得手动判断。。。
#include <cstdio> using namespace std; int main() { int T,tmp; double a,ans; scanf("%d",&T); while(T-->0) { ans=0; for(int i=0;i<12;++i) { scanf("%lf",&a); ans+=a; } ans=ans/12; tmp=int(ans*100+0.5); if(tmp%100==0) { printf("$%.0lf\n",ans); } else if(tmp%10==0) { printf("$%.1lf\n",ans); } else { printf("$%.2lf\n",ans); } } }
相关文章推荐
- B - The Suspects——HOJ
- XML解析
- 长连接和短连接分析
- 一个电商项目的Web服务化改造2:现有项目的5个问题
- 一个电商项目的Web服务化改造2:现有项目的5个问题
- 第88课:SparkStreaming从Flume Poll数据案例实战和内部源码解密
- 一个电商项目的Web服务化改造2:现有项目的5个问题
- Linux文件读写权限
- C#操作xml SelectNodes,SelectSingleNode总是返回NULL 与 xPath 介绍
- 数据结构-Trie树
- windows系统下Python3.5.1安装教程
- algorithm 题集一 (16.04.30)
- 第三方支付接口申请和开发
- 十、森林与并查集---(5)并查集按秩合并优化
- Python 深浅拷贝
- 51Nod-1135-原根
- 打劫房屋 III
- 1.Ubuntu Server下搭建LAMP环境
- 微信滑动底部菜单渐变效果
- 树上倍增实现lca