[恢]hdu 2034

2011-12-14 20:35:58

地址:http://acm.hdu.edu.cn/showproblem.php?pid=2034

题意:中文。。

mark:用了qsort和bsearch,蛮好用的。

代码:

# include <stdio.h>
# include <stdlib.h>


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


int a[110], b[110] ;
int main ()
{
int i, cnt, flag ;
int n, m ;
while (~scanf ("%d%d", &n, &m) && (n||m))
{
for (i = 0 ; i < n ; i++)
scanf ("%d", a+i) ;
for (i = 0 ; i < m ; i++)
scanf ("%d", b+i) ;
qsort (a, n, sizeof(int), cmp) ;
qsort (b, m, sizeof(int), cmp) ;
flag = 0 ;
for (i = 0 ; i < n ; i++)
if (NULL == bsearch (a+i, b, m, sizeof(int), cmp))
flag = printf ("%d ", a[i]) ;
printf (flag == 0 ? "NULL\n" : "\n") ;
}
return 0 ;
}



posted @ 2012-01-06 14:50  Seraph2012  阅读(203)  评论(0编辑  收藏  举报