Advertisement
StoneHaos

alex1

Oct 6th, 2020 (edited)
1,149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <list>
  3. #include <time.h>
  4.  
  5. using namespace std;
  6.  
  7. int main(void) {
  8.     srand(time(NULL));
  9.  
  10.     int n, m;
  11.     cin >> n >> m;
  12.     list<int> a, b;
  13.  
  14.     cout << "\na:\n";
  15.     for (int i = 0; i < n; ++ i) {
  16.         int x = rand() % 10;
  17.         a.push_back(x);
  18.         cout << x << " ";
  19.     }
  20.  
  21.     cout << "\n\nb:\n";
  22.     for (int i = 0; i < m; ++ i) {
  23.         int x = rand() % 10;
  24.         b.push_back(x);
  25.         cout << x << " ";
  26.     }
  27.  
  28.     for (auto i = a.begin(); i != a.end();) {
  29.         bool flag = true;
  30.         for (auto j = b.begin(); j != b.end(); ++ j) {
  31.             if (*i == *j)
  32.                 flag = false;
  33.         }
  34.         if (!flag) {
  35.             a.erase(i);
  36.             i = a.begin();
  37.         }
  38.         else
  39.             ++ i;
  40.     }
  41.  
  42.     cout << "\n\na(new):\n";
  43.     for (auto i = a.begin(); i != a.end(); ++ i)
  44.         cout << *i << " ";
  45.     cout << "\n";
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement