Advertisement
chel-ti

Help for Dan

May 9th, 2024
694
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <set>
  3.  
  4. const int S = 4;
  5. using namespace std;
  6.  
  7. int main() {
  8.  
  9.   setlocale(LC_ALL, "rus");
  10.   int a[S] = {}, b[S] = {}, c[S] = {};
  11.     int it = 0;
  12.  
  13.     cout << "Введите " << S << " чисел для первого массива" << endl;
  14.     for (int i = 0; i < S; i++)
  15.     {
  16.         cout << "a[" << i << "]=";
  17.         cin >> a[i];
  18.     }
  19.     cout << endl;
  20.  
  21.     cout << "Введите " << S << " чисел для второго массива" << endl;
  22.     for (int i = 0; i < S; i++)
  23.     {
  24.         cout << "b[" << i << "]=";
  25.         cin >> b[i];
  26.     }
  27.     cout << endl;
  28.  
  29.     set<int> cs;
  30.  
  31.     for (int i = 0; i < S; ++i) {
  32.         int num = 0; // Счётчик
  33.         bool check = false; // Проверка
  34.  
  35.         for (int j = 0; j < S; ++j) {
  36.  
  37.             if (a[i] == b[j])
  38.                 break;
  39.  
  40.             if (a[i] != b[j]) {
  41.                 ++num;
  42.                 if (num == S)
  43.                     check = true;
  44.                 if (check)
  45.                     cs.insert(a[i]);
  46.             }
  47.  
  48.         }
  49.     }
  50.     if (cs.empty()) {
  51.         cout << "Массивы индентичные.";
  52.         return 0;
  53.     }
  54.     cout << "Третий массив равен: " << endl;
  55.     for (auto s : cs) {
  56.         cout << s << " ";
  57.         c[it] = s;
  58.         ++it;
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement