求两个集合A,B的并集
#include <iostream>
#define N 10000
using namespace std;
typedef struct
{
int *elem;
int length;
}sqlist;
void init ( sqlist &l )
{
l.elem = new int[N];
l.length = 0;
}
void print ( sqlist l )
{
for ( int i = 0; i < l.length; i ++ )
{
cout << l.elem[i] << " ";
}
}
int main()
{
sqlist l;
init (l);
int m;
int i, j;
cin >> m;
for ( i = 0; i < m; i ++ )
{
int a;
cin >> a;
l.elem[i] = a;
l.length ++;
}
int n;
cin >> n;
for ( i = 0; i < n; i ++ )
{
int cnt = 0;
int b;
cin >> b;
for ( j = 0; j < m; j ++ )
{
if ( l.elem[j] == b )
{
cnt ++;
}
}
if ( cnt == 0 )
{
l.elem[l.length] = b;
l.length ++;
}
}
print (l);
return 0;
}