Advertisement
STANAANDREY

intersect

Apr 7th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  int a[1000],b[1000],c[2000],n,m,i,k,j,ok;
  7.  cout<<"n=";cin>>n;
  8. for (i=0;i<n;i++)
  9. cin>>a[i];
  10. cout<<"m=";cin>>m;
  11. for (i=0;i<m;i++)
  12. cin>>b[i];
  13.  
  14. k=0;
  15. for (j=0;j<m;j++)
  16. {
  17.  ok=0;
  18.  for (i=0;i<n;i++)
  19.     if (b[j]==a[i])
  20.     ok=1;
  21.     if (ok)
  22.     {
  23.         c[k]=b[j];
  24.         k++;
  25.     }
  26. }
  27. cout<<"A intersectat cu B:"<<endl;
  28. for (i=0;i<k;i++)
  29.  cout<<c[i]<<' ';
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement