Advertisement
STANAANDREY

intersect_stl

Feb 24th, 2019
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <iterator>
  5. using namespace std;
  6.  long a[1000004],b[1000004],i;
  7.  
  8. int main()
  9. {
  10.  
  11.   long n,m;
  12.   cout<<"n=";cin>>n;
  13.   for (i=1;i<=n;i++)
  14.   cin>>a[i];
  15.   cout<<"m=";cin>>m;
  16.   for (i=1;i<=m;i++)
  17.     cin>>b[i];
  18.     sort(a+1, a+n+1);
  19.     sort(b+1, b+m+1);
  20.  
  21.     vector<int> v_intersection;
  22.  
  23.     set_intersection(a+1, a+n+1,b+1, b+m+1,back_inserter(v_intersection));
  24.     for(int x : v_intersection)
  25.         cout << x << ' ';
  26. }
  27. //*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement