呵呵,很简单吧?
如果n=0并且m=0表示输入的结束,不做处理。
#include<stdio.h>
int main()
{
int n, m;
int num1[1000], num2[1000], hash[1000], i, j, t;
while( scanf( "%d%d", &n, &m ) ,n||m )
{
for( int k = 0; k < 1000; k++ )
hash[k] = 0;
for( i = 0; i < n; i++ )
scanf( "%d", &num1[i] );
for( j = 0; j < n-1; j++ )
for( i = 0; i < (n-1)-j; i++ )
if( num1[i] > num1[i+1] )
{
int t;
t = num1[i];
num1[i] = num1[i+1];
num1[i+1] = t;
}
for( j = 0; j < m; j++ )
scanf( "%d", &num2[j] );
t = n;
for( i = 0; i < n; i++ )
{
for( j = 0; j < m; j++ )
{
if( num1[i] == num2[j] )
{
hash[i] = 1;
t--;
break;
}
}
}
if( t == 0 )
printf( "NULL\n" );
else
{
for( i = 0; i < n; i++ )
{
if( hash[i] == 0 )
printf( t == 0?"%d \n":"%d ", num1[i],--t);
}
}
}
}