Advertisement
StoneHaos

nastya1

Sep 17th, 2020 (edited)
1,295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <list>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main(void) {
  9.     srand(time(NULL));
  10.  
  11.     cout << "length1 length2> ";
  12.     int len1, len2;
  13.     cin >> len1 >> len2;
  14.  
  15.     list<int> l1, l2, l;
  16.  
  17.     cout << "L1:" << endl;
  18.     for (int i = 0; i < len1; i ++) {
  19.         l1.push_back(rand() % 7);
  20.         cout << l1.back() << " ";
  21.     }
  22.  
  23.     cout << endl << endl << "L2:" << endl;
  24.     for (int i = 0; i < len2; i ++) {
  25.         l2.push_back(rand() % 7);
  26.         cout << l2.back() << " ";
  27.     }
  28.  
  29.     cout << endl << endl << "L:" << endl;
  30.     for (list<int>::iterator i = l1.begin(); i != l1.end(); i ++) {
  31.         bool flag = true;
  32.         for (list<int>::iterator j = l2.begin(); j != l2.end(); j ++)
  33.             if (*i == *j)
  34.                 flag = false;
  35.         for (list<int>::iterator j = l.begin(); j != l.end(); j ++)
  36.             if (*i == *j)
  37.                 flag = false;
  38.         if (flag) {
  39.             l.push_back(*i);
  40.             cout << l.back() << " ";
  41.         }
  42.     }
  43.  
  44.     for (list<int>::iterator i = l2.begin(); i != l2.end(); i ++) {
  45.         bool flag = true;
  46.         for (list<int>::iterator j = l1.begin(); j != l1.end(); j ++)
  47.             if (*i == *j)
  48.                 flag = false;
  49.         for (list<int>::iterator j = l.begin(); j != l.end(); j ++)
  50.             if (*i == *j)
  51.                 flag = false;
  52.         if (flag) {
  53.             l.push_back(*i);
  54.             cout << l.back() << " ";
  55.         }
  56.     }
  57.     cout << endl;
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement