解题思路:
注意事项:
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int compare(const void* a, const void* b)
{
int num_a = *(int*)a;
int num_b = *(int*)b;
if (num_a < num_b)
return -1;
else if (num_a > num_b)
return 1;
else
return 0;
}
int main()
{
int n, i,*a,*b,max=0,size;
scanf("%d", &n);
a = (int*)malloc(n * sizeof(int));
b = (int*)malloc(n * sizeof(int));
for (i = 0; i < n; i++)
scanf("%d", &a[i]);
for (i = 0; i < n; i++)
scanf("%d", &b[i]);
size = n;
qsort(a, size, sizeof(int), compare);
qsort(b, size, sizeof(int), compare);
for (i = 0; i < n; i++)
{
max += abs(a[i] - b[n - 1 - i]);
}
printf("%d", max);
return 0;
}
0.0分
0 人评分
计算质因子 (C++代码)浏览:1616 |
【金明的预算方案】 (C++代码)浏览:838 |
【明明的随机数】 (C语言代码)浏览:785 |
A+B for Input-Output Practice (VII) (C语言代码)浏览:521 |
C二级辅导-计负均正 (C语言代码)浏览:480 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:535 |
A+B for Input-Output Practice (II) (C语言代码)浏览:596 |
【偶数求和】 (C++代码)浏览:697 |
C语言训练-斐波纳契数列 (C语言代码)浏览:593 |
1199题解浏览:653 |