#include <cstdio>
#include <cmath>
using namespace std;
int a[50];
void work(int p,int r){
if(p<r){
int i=p-1,j,temp;
for(j=p;j<r;j++){
if(a[j]>=a[r]){
i++;
temp=a[i];a[i]=a[j];a[j]=temp;
}
}
temp=a[i+1];
a[i+1]=a[r];
a[r]=temp;
work(p,i);
work(i+2,r);
}
}
int main(){
int i;
sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
work(0,n-1);
for(i=0;i<n-1;i++)
sum+=abs(a[i+1]-a[i]);//abs stdlib.h
printf("%d\n",sum);
return 0;
}
//输入:10 23 435 12 345 3123 43 456 12 32 -100
//输出
//答案:3223
电子学会 青少年编程等级考试 C语言 1级
电子学会青少年等级考试C语言(二级)
电子学会 全国青少年软件编程等级考试(三级--八级)
电子学会 全国青少年软件编程等级考试标准 十级标准及相关资料
电子学会 青少年编程等级考试 C语言 1级-10级 学习资料集
电子学会 青少年编程等级考试 C语言 1级-10级 学习资料集_dllglvzhenfeng的博客-CSDN博客