Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define IN freopen("in.txt", "r", stdin);
- #define OUT freopen("out.txt", "w", stdout);
- #define LL long long int
- #define MX 500001
- #define max3(a, b, c) max(a, max(b, c)
- #define min3(a, b, c) min(a, min(b, c)
- #define max4(a, b, c, d) max(a, max3(b, c, d)
- #define min4(a, b, c, d) min(a, min3(b, c, d)
- #define EPS 1e-9
- #define MOD 1000000007
- #define PI 2.0 * acos(0.0)
- typedef pair <int, int> PII;
- int main() {
- //IN OUT //ThisIsForDebuggingPurposes
- int a[4] = {1, 7, 13, 37}; // first sub-array
- int b[3] = {12, 18, 33}; // 2nd sub-array
- int c[7]; // mergered array
- for (int i = 0, j = 0, k = 0; i < 4 || j < 3;) { // i used for a & j used for b & k used for c
- if (i < 4 && j < 3) {
- if (a[i] < b[j]) { // i have to choose value from unused element of both sub-array
- c[k] = a[i];
- i++;
- k++;
- }
- else {
- c[k] = b[j];
- j++;
- k++;
- }
- }
- else if (i < 4) { // only array a is left, array b is fully used, so i can take value only from array a
- c[k] = a[i];
- i++;
- k++;
- }
- else if (j < 3) { // only array a is left, array b is fully used, so i can take value only from array b
- c[k] = b[j];
- j++;
- k++;
- }
- }
- for (int i = 0; i < 7; i++)
- cout << c[i] << " ";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement