Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n1, n2, i;
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- cin >> n1 >> n2;
- int* a = new int[n1], * b = new int[n2], * c = new int[n1 + n2];
- for (i = 0; i < n1; i++)
- {
- cin >> a[i];
- }
- for (i = 0; i < n2; i++)
- {
- cin >> b[i];
- }
- int j = 0, k = 0, h = 0;
- while (j < n1 && k < n2)
- {
- if (a[j] <= b[k]) c[h++] = a[j++];
- else c[h++] = b[k++];
- }
- while (j < n1) c[h++] = a[j++];
- while (k < n2) c[h++] = b[k++];
- for (i = 0; i < n1 + n2; i++)
- {
- cout << c[i] << " ";
- }
- }
Add Comment
Please, Sign In to add comment