forked from r0drigopaes/paa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_merge.cpp
57 lines (42 loc) · 873 Bytes
/
simple_merge.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <bits/stdc++.h>
using namespace std;
vector<int> simple_merge(vector<int> &a, vector<int> &b)
{
int total, j, k;
total = a.size() + b.size();
j = 0;
k = 0;
vector<int> c(total);
a.push_back(INT_MAX);
b.push_back(INT_MAX);
for (int i = 0; i < total; i++)
{
c[i] = (a[j] < b[k]) ? a[j++] : b[k++];
}
a.erase(a.end() - 1);
b.erase(b.end() - 1);
return c;
}
int main()
{
int n1, n2, x;
vector<int> a, b;
scanf("%d%d", &n1, &n2);
for (int i = 0; i < n1; ++i)
{
scanf("%d", &x);
a.push_back(x);
}
for (int i = 0; i < n2; ++i)
{
scanf("%d", &x);
b.push_back(x);
}
vector<int> result;
result = simple_merge(a, b);
for (int i = 0; i < result.size(); ++i)
{
printf("%d\n", result[i]);
}
return 0;
}