Advertisement
Wazedrifat

rakib.cpp

Feb 19th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define IN freopen("in.txt", "r", stdin);
  5. #define OUT freopen("out.txt", "w", stdout);
  6. #define LL long long int
  7. #define MX 500001
  8. #define max3(a, b, c) max(a, max(b, c)
  9. #define min3(a, b, c) min(a, min(b, c)
  10. #define max4(a, b, c, d) max(a, max3(b, c, d)
  11. #define min4(a, b, c, d) min(a, min3(b, c, d)
  12. #define EPS 1e-9
  13. #define MOD 1000000007
  14. #define PI 2.0 * acos(0.0)
  15. typedef pair <int, int> PII;
  16.  
  17. int main() {
  18.     //IN OUT        //ThisIsForDebuggingPurposes
  19.     int a[4] = {1, 7, 13, 37};  //  first sub-array
  20.     int b[3] = {12, 18, 33};    //  2nd sub-array
  21.  
  22.     int c[7];   //  mergered array
  23.  
  24.     for (int i = 0, j = 0, k = 0; i < 4 || j < 3;) {    //  i used for a & j used for b & k used for c
  25.         if (i < 4 && j < 3) {
  26.             if (a[i] < b[j]) {  //  i have to choose value from unused element of both sub-array
  27.                 c[k] = a[i];
  28.                 i++;
  29.                 k++;
  30.             }
  31.             else {
  32.                 c[k] = b[j];
  33.                 j++;
  34.                 k++;
  35.             }
  36.         }
  37.         else if (i < 4) {   //  only array a is left, array b is fully used, so i can take value only from array a
  38.             c[k] = a[i];
  39.             i++;
  40.             k++;
  41.         }
  42.         else if (j < 3) {   //  only array a is left, array b is fully used, so i can take value only from array b
  43.             c[k] = b[j];
  44.             j++;
  45.             k++;
  46.         }
  47.     }
  48.  
  49.     for (int i = 0; i < 7; i++)
  50.         cout << c[i] << " ";
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement