此处的c和a指向同一块内存空间,改变c就是改变a,反之亦然,此处是为了方便看这么写的,如果不想c和a指向同一空间请分别开辟空间(即不如此写c=a=malloc)
cs
#include<stdio.h>
#include<stdlib.h>
int com( const void* c1,const void* c2)
{
return (*(int*)c1 - *(int*)c2);
}
void main()
{
int n, m,*c, * a, * b,i,j,dst;
while (~scanf_s("%d%d", &n, &m) && (n != 0 || m != 0))
{
c=a = (int*)malloc(n * sizeof(int)), b = (int*)malloc(m * sizeof(int)),dst=0;
for (i = 0; i < n; i++)scanf_s("%d", a + i);
for (i = 0; i < m; i++)scanf_s("%d", b + i);
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
if (a[i] == b[j])break;
if (j == m)c[dst++] = a[i];
}
if (dst == 0)printf("NULL");
else
{
qsort(c, dst, sizeof(int), com);
for (i = 0; i < dst; i++)printf("%d ", c[i]);
}
printf("\n");
}
}