杭电oj 2034 人见人爱A-B C语言

#include
#include

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");
	}
}

你可能感兴趣的:(c语言,算法,开发语言)