Advertisement
arfin97

set - intersection uri 1104

Oct 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define d(x) cout << #x << " = " << (x) << endl
  4. #define fr freopen("in.txt", "r", stdin);
  5. #define fw freopen("out.txt", "w", stdout);
  6. #define mem(x) memset((x), 0, sizeof((x)));
  7. #define ll long long
  8. #define siz 100000
  9. #define MAX 100005
  10.  
  11. int main() {
  12.     //fr; fw;
  13.     //////////////////////MAIN//////////////////////
  14.     int n, m;
  15.     while(cin >> n >> m){
  16.         if(n == 0 && m == 0) break;
  17.         set<int> first; //prothom set
  18.         set<int> second; //ditio set
  19.         //prothom set er input nitesi
  20.         for(int i = 0; i < n; i++){
  21.             // cin >> first[i];
  22.             int input;
  23.             cin >> input;
  24.             first.insert(input);
  25.         }
  26.         //ditiyo set er input nitesi
  27.         for(int i = 0; i < m; i++){
  28.             // cin >> second[i];
  29.             int input;
  30.             cin >> input;
  31.             second.insert(input);
  32.         }
  33.         //eta amar intersection vector, and size dite hobe duita set er size er soman.
  34.         vector<int> v(m+n);
  35.         //set_intersection function iterator diye kaj kore. tai ekta iterator banate hobe.
  36.         vector<int>::iterator it;
  37.         //then iterator e assigne kore set intersection chalalam.
  38.         it= set_intersection (first.begin(), first.end(), second.begin(), second.end(), v.begin());
  39.         //oita chalale size lastly (m+n) er soman thake. sekhan theke [kichu ekta kore bad diye] size thik korte hoy
  40.         //still confused how it works though.
  41.         v.resize(it-v.begin());
  42.  
  43.         //std::cout << "The intersection has " << (v.size()) << " elements:\n";
  44.         //cout << first.size() << endl;
  45.         //cout << second.size() << endl;
  46.        
  47.         if(first.size() <= second.size()) cout << (first.size()-v.size()) << endl;
  48.         if(second.size() < first.size()) cout << (second.size()-v.size()) << endl;
  49.     }
  50.     return 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement