Advertisement
Guest User

Țaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa

a guest
Mar 26th, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream f("bac.txt");
  6.  
  7. void Read(int& n, int& m, int a[100], int b[100])
  8. {
  9.     f >> n >> m;
  10.     for(int i = 0; i < n; ++i)
  11.         f >> a[i];
  12.     for(int j = 0; j < m; ++j)
  13.         f >> b[j];
  14. }
  15.  
  16. void Ord(int n, int m, int a[100], int b[100])
  17. {
  18.     int i1 = 0, i2 = 0, x;
  19.  
  20.     cout << (x = (a[i1] < b[i2] ? a[i1++] : b[i2++])) << " ";
  21.     while(i1 < n && i2 < m)
  22.     {
  23.         if(a[i1] < b[i2])
  24.         {
  25.             if(x & 1)
  26.                 cout << (x = a[i1]) << " ";
  27.             ++i1;
  28.         }
  29.         else
  30.         {
  31.             if(!(x & 1))
  32.                 cout << (x = b[i2]) << " ";
  33.             ++i2;
  34.         }
  35.     }
  36.  
  37.     if((x & 1) && i1 < n)
  38.         cout << a[i1];
  39.     if(!(x & 1) && i2 < m)
  40.         cout << b[i2];
  41. }
  42.  
  43. int main()
  44. {
  45.     int n, m, a[100], b[100];
  46.     Read(n, m, a, b);
  47.     Ord(n, m, a, b);
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement