Fortune Telling Collection - Comprehensive fortune-telling - To calculate the intersection, union and complement of two integer sets A and B, the intersection, union and complement in A need to be written as a separate function.

To calculate the intersection, union and complement of two integer sets A and B, the intersection, union and complement in A need to be written as a separate function.

# include & ltbits/stdc++。 h & gt

# Definition MX 1000

Use namespace std

int main()

{

int n,m,a[2 * MX + 10],b[MX + 10],c[MX + 10],I,j,p = 0,d[MX + 10],f = 0;

CIN & gt; & gtn;

for(I = 1; I < = n; i++)

{

CIN & gt; & gta[I];

}

CIN & gt; & gtm;

for(I = 1; I<= m;; i++)

{

CIN & gt; & gtb[I];

}

Sorting (b+1, b+m+1);

sort(a + 1,a+n+ 1);

for(I = 1; I < = n; i++)

{

c[I]= a[I];

}

for(I = 1; I<= m;; i++)

{

d[I]= b[I];

}

for(I = 1; I < = n; i++)

{

for(j = 1; j & lt= m; J++)// Find the intersection

{

if (a[i] == b[j])

{

cout & lt& lta[I]& lt; & lt" ";

f = 1;

}

}

}

If (f == 1)

{

cout & lt& ltendl

}

for(I = 1; I<= m;; i++)

{

a[n+I]= b[I];

}

Sorting (a+1, a+n+m+1);

for(I = 1; I< = n+m; I++)// Find union

{

cout & lt& lta[I]& lt; & lt" ";

while(a[i] == a[i + 1])

{

i++;

}

}

cout & lt& ltendl

int cnt

for(I = 1; I < = n; I++)// congruent set

{

CNT = 0;

for(j = 1; j & lt= m; j++)

{

if (c[i]! = d[j])

{

cnt++;

}

}

If (cnt == m)

{

cout & lt& ltc[I]& lt; & lt" ";

}

}

Returns 0;

}

The function is to divide them into three parts and put them outside.