#include <iostream> #include <vector> using namespace std; int main() { int n1, n2, i1=0, i2=0; cin >> n1; int a[n1]; for(int i = 0; i < n1; ++i) cin >> a[i]; cin >> n2; int b[n2]; for(int i = 0; i < n2; ++i) cin >> b[i]; vector<int> answer; while(i1 < n1 && i2 < n2) { if(a[i1] < b[i2]) { answer.push_back(a[i1]); ++i1; } else if(a[i1] > b[i2]) { answer.push_back(b[i2]); ++i2; } } while(i1 < n1) { answer.push_back(a[i1]); ++i1; } while(i2 < n2) { answer.push_back(b[i2]); ++i2; } for(int num : answer) cout << num << " "; return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter