Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我也不知道为什么,凑了个程序就AC了,对精度的问题我也没有很好理解In Reply To:那你就帮忙指出来吧!我也想学习一下 Posted by:zerocool_08 at 2005-10-14 10:05:02 #include "stdio.h" int main(void) { double sum,ave,a[1010],s1,s2; int n,i,temp; while(scanf("%d",&n)==1&&n) { sum=0; for(i=0;i<n;i++) scanf("%lf",&a[i]),sum+=a[i]; ave=sum/n; temp=(int)(ave*100+0.5); ave=temp/100.0; for(i=0,s1=0,s2=0;i<n;i++) { if(a[i]>ave) s1+=a[i]-ave; else s2+=ave-a[i]; } sum=s1<s2? s1:s2; printf("$%.2lf\n",sum); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator