HDOJ 1040 qsort

注意 compare 函数的写法,行末不留空格。

/* qsort */
# include <stdio.h>
# include <stdlib.h>

int compare(const void * a, const void * b)
{
return (*(int *)a) - (*(int *)b);
}

int main()
{
int T, N, i;
int a[1001];

scanf("%d", &T);
while (T--)
{
scanf("%d", &N);
for (i = 0; i < N; ++i)
scanf("%d", &a[i]);
qsort(a, N, sizeof(int), compare);
--N;
for (i = 0; i < N; ++i)
printf("%d ", a[i]);
printf("%d\n", a[i]);
}

return 0;
}

你可能感兴趣的:(sort)