10137 (The trip)

0 views
Skip to first unread message

May

unread,
Jul 1, 2011, 3:16:34 PM7/1/11
to ACM-CPC-MUST
/*
Question ID: 10137 (The trip)
Tool: DevC++ 7.3.1.3
Rank: 1190
Time: 0.016
*/
#include <iostream>
#include <cmath>
using namespace std;

#define MAX 1000

int main(){
double num,money[MAX],total,temp,avg,give,rec,result;
int i;

while(true){
total=avg=give=rec=result=0;

cin >> num;
if(num==0) break;
for(i=0;i<num;i++){
cin >> money[i];
total+=money[i];
}

avg = total/num*100;
temp = floor(avg);
temp = avg-temp;
if(temp>=0.5) avg=ceil(avg);
else avg=floor(avg);

avg/=100;

for(i=0;i<num;i++){
if(money[i]==avg) continue;
else if(money[i]<avg){
rec+= (avg-money[i]);
}else{
give+= (money[i]-avg);
}
}

if(give==0||((give>rec)&&(rec!=0))){
result = rec;
}else{
result = give;
}

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << "$" << result << endl;
}
return 0;
}
Reply all
Reply to author
Forward
0 new messages