Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int n,m,a[100000],b[100000],ela,elb;
- int contor=0;
- int main()
- {
- cin >> n;
- for(int i=0; i<n; i++)
- {
- cin >> a[i];
- }
- cin >> m;
- for(int i=0; i<m; i++)
- {
- cin >> b[i];
- }
- int p1 = 0;
- int p2 = 0;
- while(p1 < n && p2 < m)
- {
- if (a[p1] < b[p2])
- {
- cout << a[p1] << ' ';
- p1++;
- continue;
- }
- if (a[p1] > b[p2])
- {
- cout << b[p2] << ' ';
- p2++;
- continue;
- }
- if (a[p1] == b[p2])
- {
- cout << b[p2] << ' ';
- p1++;
- p2++;
- }
- }
- while(p1<n)
- {
- cout << a[p1] << ' ';
- p1++;
- }
- while(p2<m)
- {
- cout << b[p2] << ' ';
- p2++;
- }
- cout << '\n';
- p1 = 0;
- p2 = 0;
- while(p1 < n && p2 < m)
- {
- while(a[p1] != b[p2] && (p1 < n && p2 < m))
- {
- while (a[p1] < b[p2]) p1++;
- while (a[p1] > b[p2]) p2++;
- }
- if (a[p1] == b[p2])
- {
- cout << b[p2] << ' ';
- p1++;
- p2++;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement