~cpp #include <iostream> using namespace std; #include <vector> #include <numeric> int num, i, temp1; double temp_max,temp_min; vector<double> test; void process() { cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout.precision(2); double max=0.0, min=0.0; num = int(accumulate(test.begin(),test.end(),0.0)/test.size()*1000); temp_max = double((num + 10)/10)/100; temp_min = double((num)/10)/100; if(num % 10 == 0) temp_max = temp_min; for(i = 0; i < test.size(); i++) { if(test[i] > temp_max) { max += test[i] - temp_max; } else if( test[i] < temp_min) { min += temp_min - test[i]; } } if(min > max) max = min; cout << "$" << max << endl; } int main() { cin >> num; while(num) { for(i = 0; i <num; i++) { cin >> temp_max; test.push_back(temp_max); } process(); test.clear(); cin >> num; } return 0; }