uva :: Programming Challenges :: Chapter 1-10137 - The Trip

 1 /* 
 2  * File:   10137.cpp
 3  * Author: GongZhi
 4  * Problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=29&page=show_problem&problem=1078
 5  * Created on 2009年7月25日, 下午9:29
 6  */
 7 
 8 #include <stdlib.h>
 9 #include <string.h>
10 #include <iostream>
11 #include <string>
12 #include <vector>
13 #include <map>
14 #include <queue>
15 using namespace std;
16 
17 /*
18  *
19  */
20 double data[2000];
21 char temp[100];
22 int main() {
23     int n,i;
24     double t,ans1,ans2;
25     while(scanf("%d",&n),n){
26         t=0;
27         for(i=0;i<n;i++){
28             scanf("%lf",&data[i]);
29             t+=data[i];
30         }
31         t/=n;
32         sprintf(temp,"%.2f",t);
33         sscanf(temp,"%lf",&t);
34         ans1=0;ans2=0;
35         for(i=0;i<n;i++)
36             if(t>data[i])ans1=ans1+t-data[i];
37             else ans2=ans2-t+data[i];
38         if(ans1<ans2)printf("$%.2f\n",ans1);
39         else printf("$%.2f\n",ans2);
40     }
41     return 0;
42 }
43 
44 

posted on 2009-07-25 21:57 gong 阅读(1186) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2009年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

导航

统计

常用链接

留言簿(6)

随笔档案

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜