http://acm.hit.edu.cn/ojs/show.php?Proid=1370&Contestid=0
上面是链接~~
我的代码
#include <stdio.h>
#include <stdlib.h>
#define SIZE 100000 /* the max number of packets*/
int main (void)
{
int packet[SIZE];
int num, totall, result, hold;
int i;
scanf("%d", &num);
totall = 0;
result = 0;
while(num != -1)
{
for(i = 0; i <= num - 1; i++)
{
scanf ("%d", &packet[i]);
totall += packet[i];
}
if(totall % num != 0) /* fail */
{
printf ("%d\n", -1);
}
else
{
hold = totall / num; /* the average*/
for(i = 0; i <= num - 1; i++)
{
result = hold >= packet[i]? hold - packet[i]: packet[i] - hold;
}
printf ("%d\n", result);
}
scanf("%d", &num);
totall = 0;
result = 0;
}
return 0;
}
[此贴子已经被作者于2007-11-3 21:11:37编辑过]