拜访朋友

软件工程马搏 edited 4 年前

include

include

int main()
{
int m,t,n,i,j,s,a[501],c;
scanf(“%d”,&m);
for (t=0;t<m;t++)
{
s=0;
scanf(“%d”,&n);
for (i=0;i<n;i++)
scanf(“%d”,&a[i]);
for (i=0;i<n-1;i++)
for (j=i+1;ja[j])
{
c=a[i];a[i]=a[j];a[j]=c;
}
for (i=0;i<n;i++)
s+=fabs(a[n/2]-a[i]);
printf(“%d\n”,s);
}
}

Comments