Raslboyy

Untitled

May 28th, 2021
1,156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7.   freopen("input.txt", "r", stdin);
  8.   freopen("output.txt", "w", stdout);
  9.  
  10.   int a[5];
  11.   int b[5];
  12.   int c[10];
  13.  
  14.   int na, nb;
  15.   cin >> na;
  16.   for (int i = 0; i < na; i++)
  17.     cin >> a[i];
  18.   cin >> nb;
  19.   for (int i = 0; i < nb; i++)
  20.     cin >> b[i];
  21.   int count = 0;
  22.  
  23.   for (int i = 0; i < na; i++)
  24.     for (int j = 0; j < nb; j++)
  25.       if (a[i] == b[j]) {
  26.         c[count] = a[i];
  27.         count++;
  28.         b[j] = -100000000;
  29.       }
  30.  
  31.   cout << count << '\n';
  32.   for (int i = 0; i < count; i++)
  33.     cout << c[i] << ' ';
  34.   cout << '\n';
  35.  
  36.   return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment