Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n,m,a[20],b[20],c[20];
- cout<<"n=";
- cin>>n;
- cout<<"m=";
- cin>>m;
- for (int i=0;i<n;i++)
- {
- cout<<"a["<<i<<"]=";
- cin>>a[i];
- }
- for (int i=0;i<m;i++)
- {
- cout<<"b["<<i<<"]=";
- cin>>b[i];
- }
- int i=0,j=m-1,k=0;
- while (i<n&&j>=0)
- {
- if (a[i]%2==0&&b[j]%2==0)
- {
- if (a[i]<b[j])
- {
- c[k]=a[i];
- i++;
- k++;
- }
- else
- {
- c[k]=b[j];
- j--;
- k++;
- }
- }
- else
- {
- if (a[i]%2==0)
- {
- c[k]=a[i];
- i++;
- k++;
- }
- else
- {
- if (b[j]%2==0)
- {
- c[k]=b[j];
- j--;
- k++;
- }
- else
- {
- i++;
- j--;
- }
- }
- }
- }
- while (j>=0)
- {
- if (b[j]%2==0)
- {
- c[k]=b[j];
- k++;
- }
- j--;
- }
- while (i<n)
- {
- if (a[i]%2==0)
- {
- c[k]=a[i];
- k++;
- }
- i++;
- }
- for (int i=0;i<k;i++)
- {
- cout<<c[i]<<" ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement