1#include <stdio.h>2#include <Set>3 using namespacestd;4 Const intn= ++5;5 6 intn,m;7 intA[n], b[n];8 9 intMain ()Ten { One intI, J; A while(SCANF ("%d", &n) = =1) - { - Set<int> s;//Save and set the Set<int> Cha;//Save Difference Set - intlx=0, ly=0; - BOOLf=0; - + for(i=0; i<n; i++) - { +scanf"%d", &a[i]); A S.insert (A[i]); at Cha.insert (A[i]); - } -lx=s.size (); -scanf"%d", &m); - for(j=0; j<m; J + +) - { inscanf"%d", &b[j]); - S.insert (B[j]); toly=s.size (); + if(LY==LX)//Insert failed, description is intersection of element, output - { the cha.erase (B[j]); * if(!f) $ {Panax Notoginsengf=1; -printf"%d", B[j]); the } + Else Aprintf"%d", B[j]); the } + Else -lx=ly; $ } $ if(f) -Puts""); - the //output and set -f=0;Wuyi for(Set<int>::iterator It=s.begin (); It!=s.end (); it++) the { - if(!f) Wu { -printf"%d", *it); Aboutf=1; $ } - Else -printf"%d", *it); - } A if(f) +Puts""); the - //Output Difference Set $f=0; the for(Set<int>::iterator Itt=cha.begin (); Itt!=cha.end (); itt++) the { the if(!f) the { -printf"%d", *ITT); inf=1; the } the Else Aboutprintf"%d", *ITT); the } the if(f) thePuts""); + } - return 0; the}
Intersection, set, and difference sets