标签:blog class code c color http
http://acm.hdu.edu.cn/showproblem.php?pid=4493
题意是输入12个数据,让你求平均值,但是要去除尾零,就像100.00只要输出100
其实这题有点不严密,像这组数据
2
100.995
100.995
100.995
100.995
100.995
100.995
100.995
100.995
100.995
100.995
100.995
100.995
输出100,其他可以过的输出100.10以及101都可以
用自己的方法死活不可以过,上网搜了一下,都是各显神通啊,题目也是有点坑
写个题解记录下,也是发现一种方法(+0.005)
遇到题,还是不能急,慢慢想解决办法。。。。。。。。。
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33 |
#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ double
n,m,sum; int
i,j,t; scanf("%d",&t); while(t--) { sum=0.0; for(i=0;i<12;i++) { scanf("%lf",&n); sum+=n; }//printf("%lf^",sum); sum/=12.0; //sum+=0.005; int
data; data=(int)((sum+0.005)*100); int
a,b,c; a=(data%10); b=(data/10%10);//printf("%d%d^",a,b); if(a==0&&b==0) printf("$%d\n",(int
)sum); else
if(a==0) printf("$%.1lf\n",sum); else
printf("$%.2lf\n",sum); } return
0;} |
hdu 4493 Tutor(简单处理题),布布扣,bubuko.com
标签:blog class code c color http
原文地址:http://www.cnblogs.com/ccccnzb/p/3723869.html