#include<stdio.h>
#include<stdlib.h>
void bubble_sort(int num[], int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (num[j] > num[i]) {
int temp = num[j];
num[j] = num[i];
num[i] = temp;
}
}
}
}
int main(){
int time,n,mid,j,k,all = 0;
int num[500];
scanf("%d",&time);
for(int i = 0;i<time;i++){
all = 0;
scanf("%d",&n);
for( j = 0;j<n;j++){
scanf("%d",&num[j]);
}
bubble_sort(num,j);
mid = num[j/2];
for(k=0;k<n;k++){
all = all+abs(mid-num[k]);
}
printf("%d",all);
}
}
#include
#include
void bubble_sort(int num[], int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (num[j] > num[i]) {
int temp = num[j];
num[j] = num[i];
num[i] = temp;
}
}
}
}
int main(){
int time,n,mid,j,k,all = 0;
int num[500];
scanf("%d",&time);
for(int i = 0;i
all = 0;
scanf("%d",&n);
for( j = 0;j
scanf("%d",&num[j]);
}
bubble_sort(num,j);
mid = num[j/2];
for(k=0;k
all = all+abs(mid-num[k]);
}
printf("%d",all);
}}
每輸出一次要換行口屋
#include
#include
void bubble_sort(int num[], int n) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
if (num[j] > num[i]) {
int temp = num[j];
num[j] = num[i];
num[i] = temp;
}
}
}
}
int main(){
int time,n,mid,j,k,all = 0;
int num[500];
scanf("%d",&time);
for(int i = 0;i
all = 0;
scanf("%d",&n);
for( j = 0;j
scanf("%d",&num[j]);
}
bubble_sort(num,j);
mid = num[j/2];
for(k=0;k
all = all+abs(mid-num[k]);
}
printf("%d",all);
}}
每輸出一次要換行口屋
原來!!感謝解惑~