#include<iostream> #include<algorithm> using namespace std; int main() { int n,place,i; cin>>n; int a[n]; for(i=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); int total=0; place=a[n/2]; for(i=0;i<n;i++) { total+=abs(place-a[i]); } cout<<total<<endl; }
标签:std,int,最小,距离,place,include From: https://www.cnblogs.com/weinan030416/p/17067845.html