两个数组A、B,求在A中出现而不在B中的数(求不相交集)

#include <iostream>
using namespace std;

#define M 6
#define N 4

void CompArr( int arr1[], int arr2[] )
{
	int meet;
	for( int i = 0; i < M; i++ )
	{
		meet = 0;
		for( int j = 0; j < N; j++ )
		{	
			if( arr1[i] == arr2[j] )
			{	
				meet = 1;
				break;
			}
		}

		if( !meet ){
			cout << arr1[i] << " ";
		}
	}
}

void main(){
	int arr1[M] = { 1, 2, 3, 4, 6, 7 };
	int arr2[N] = { 1, 3, 4, 5 };

	cout << "A not B: ";
	CompArr( arr1, arr2 );
	cout << endl;

	system( "PAUSE");
}

点赞