STANAANDREY

9 16 2019 pb4

Sep 16th, 2019
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("bac.in");
  6.  
  7. int main()
  8. {
  9.     int n, m, a[1000], b[1000], c[2000], i, j = 0, k = 0, x;
  10.     fin >> m >> n;
  11.     for (int i = 0; i < m; i++)
  12.     {
  13.         fin >> x;
  14.         if (x % 2 == 0)
  15.         {
  16.             a[j] = x;
  17.             j++;
  18.         }
  19.     }
  20.     m = j;
  21.     j = 0;
  22.     for (int i = 0; i < n; i++)
  23.     {
  24.         fin >> x;
  25.         if (x % 2 == 0)
  26.         {
  27.             b[j] = x;
  28.             j++;
  29.         }
  30.     }
  31.     n = j;
  32.     i = m - 1;
  33.     j = n - 1;
  34.     while (i != -1 && j != -1)
  35.     {
  36.         if (a[i] > b[j])
  37.         {
  38.             c[k++] = a[i];
  39.             i--;
  40.         }
  41.         else if (a[i] == b[j])
  42.         {
  43.             c[k++] = a[i];
  44.             i--;
  45.             j--;
  46.         }
  47.         else
  48.         {
  49.             c[k++] = b[j];
  50.             j--;
  51.         }
  52.     }
  53.     while (i != -1)
  54.     {
  55.         c[k++] = a[i];
  56.         i--;
  57.     }
  58.     while (j != -1)
  59.     {
  60.         c[k++] = b[j];
  61.         j--;
  62.     }//*/
  63.     for (i = 0; i < k; i++)
  64.         cout << c[i] << ' ';//*/
  65.     return 0;
  66. }
Add Comment
Please, Sign In to add comment