fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<set>
  5. using namespace std;
  6. int NumberofElementsInIntersection (int a[], int b[], int n, int m ){
  7. // Your code goes here
  8. int i=0,j=0,count=0;
  9. set<int> s1,s2;
  10. vector<int> v(n+m);
  11. vector<int>::iterator it;
  12. for(i=0;i<n;i++)
  13. s1.insert(a[i]);
  14. for(i=0;i<m;i++)
  15. s2.insert(b[i]);
  16. it=set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),v.begin());
  17. return (it-v.begin());
  18. }
  19.  
  20. int main(){
  21. int a[] = {1, 2, 3, 4, 5, 6};
  22. int b[] = {3, 4, 5, 6, 7};
  23. cout<<NumberofElementsInIntersection(a,b,6,5);
  24. return 0;
  25. }
Success #stdin #stdout 0s 5536KB
stdin
Standard input is empty
stdout
4