I agree about assuming the judges error, but I don't know what else to do at this point since I still can't find anything that breaks my proggie And besides its a computer judge not a human judge, and there is a disclaimer saying that it isn't perfect.
And ygfperson, I just realized that unfortunately your program doesn't work on all cases. It turns out that you do need to calculate the difference for those below the average. Take for instance the case of 3 students who pay $1.00, $3.00, and $3.00. The average is $2.333 which means the below average need to pay $1.33 and the above average need to receive $1.32. So the answer needs to be $1.33 but your program prints out $1.32.
Anyways, here is my latest code that got turned down:
Code:
#include<iostream>
#include<vector>
using namespace std;
int max(int x, int y) {if (x>y) return x; else return y;}
int min(int x, int y) {if (x<y) return x; else return y;}
int main()
{
vector<int> vecF; // vector holding each amount paid
while (1)
{
int num; // number of students
int x;
int total=0; // total amount spent in pennies
int more=0; // amount over the average spent in pennies
int less=0; // amount under the average spent in pennies
bool round=false; // average came out evenly or not
vecF.clear();
cin>>num;
if (!num)
break;
for (x=0; x<num; x++)
{
double d;
cin>>d;
d*=100;
vecF.push_back(int(d));
total+=(vecF[x]);
}
if (total%num!=0)
round=true;
total/=num;
for (x=0; x<vecF.size(); x++)
{
if (round && vecF[x]>=total+1)
more+=(vecF[x]-(total+1));
else if (!round && vecF[x]>=total)
more+=(vecF[x]-total);
else
less+=(total-vecF[x]);
}
less=max(less,more);
cout<<"$"<<less/100<<".";
if (less%100<10)
cout<<"0";
cout<<less%100<<endl;
}
return 0;
}