Raslboyy

Untitled

May 28th, 2021
1,152
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. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.  
  8.   ifstream fin("input.txt");
  9.   ofstream fout("output.txt");
  10.  
  11.   int a[5];
  12.   int b[5];
  13.   int c[10];
  14.  
  15.   int na, nb;
  16.   fin >> na;
  17.   for (int i = 0; i < na; i++)
  18.     fin >> a[i];
  19.   fin >> nb;
  20.   for (int i = 0; i < nb; i++)
  21.     fin >> b[i];
  22.   int count = 0;
  23.  
  24.   for (int i = 0; i < na; i++)
  25.     for (int j = 0; j < nb; j++)
  26.       if (a[i] == b[j]) {
  27.         c[count] = a[i];
  28.         count++;
  29.         b[j] = -100000000;
  30.       }
  31.  
  32.   fout << count << '\n';
  33.   for (int i = 0; i < count; i++)
  34.     fout << c[i] << ' ';
  35.   fout << '\n';
  36.  
  37.   return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment