~cpp #include <iostream> #include <cmath> using namespace std; #define MAX_STU 1000 double student[MAX_STU+1]; int student_num, i, j, sum, average; double least, most; double calculate() { sum = 0; least = most = 0.0; for(j=1; j<student_num+1; j++) { student[j] = student[j]*100; sum = sum + student[j]; } average = sum/student_num; for(j=1; j<student_num+1; j++) { if(student[j]<average) least = least + average - student[j]; if(student[j]>average+1) most = most + student[j] - average - 1; } if(most <least ) return least; return most; } int main() { cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout.precision(2); while(cin>>student_num) { if(student_num==0) break; for(i=1; i<student_num+1; i++) cin >> student[i]; cout << "$" << calculate()/100 <<endl; } return 0; }