/* The trip 注意特殊数据的处理,误差不超过0.01即可。 */#include<iostream> #include<cstdio> using namespace std; double a[1005]; int main() { // freopen("./pcio/110103.inp","r",stdin); int n,i; while(~scanf("%d",&n)) { if(n==0) break; double sum=0.00,sum1=0.00,sum2=0.00; int j=0,k=0; for(i=0; i<n; i++) { scanf("%lf",a+i); sum+=a[i]; } double avg=sum/n; avg = (long) (avg * 100 + 0.5) / 100.00; for(i=0; i<n; i++) { if(a[i]>avg) sum1+=a[i]-avg; else sum2+=avg-a[i]; } cout.precision(2); cout.setf(ios::fixed | ios::showpoint); if(sum1>0 && sum2>0) { if(sum1>sum2) cout<<'$'<<sum2<<endl; else cout<<'$'<<sum1<<endl; } else { if(sum1==0 && sum2==0) cout<<'$'<<0.0<<endl; else if(sum1==0) { for(i=0;i<n;i++) if(a[i]>avg) sum1+=(a[i]-avg-0.01); cout<<'$'<<sum1<<endl; } else if(sum2==0) { for(i=0;i<n;i++) if(a[i]<avg) sum2+=(avg-a[i]-0.01); cout<<'$'<<sum2<<endl; } } } return 0; }
时间: 2024-09-29 04:50:32