Advertisement
Norbysweg

T49

Jan 29th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n,m,a[20],b[20],c[20];
  8.     cout<<"n=";
  9.     cin>>n;
  10.     cout<<"m=";
  11.     cin>>m;
  12.     for (int i=0;i<n;i++)
  13.     {
  14.         cout<<"a["<<i<<"]=";
  15.         cin>>a[i];
  16.     }
  17.     for (int i=0;i<m;i++)
  18.     {
  19.         cout<<"b["<<i<<"]=";
  20.         cin>>b[i];
  21.     }
  22.     int i=0,j=m-1,k=0;
  23.     while (i<n&&j>=0)
  24.     {
  25.         if (a[i]%2==0&&b[j]%2==0)
  26.         {
  27.             if (a[i]<b[j])
  28.             {
  29.                 c[k]=a[i];
  30.                 i++;
  31.                 k++;
  32.             }
  33.             else
  34.             {
  35.                 c[k]=b[j];
  36.                 j--;
  37.                 k++;
  38.             }
  39.         }
  40.         else
  41.         {
  42.             if (a[i]%2==0)
  43.             {
  44.                 c[k]=a[i];
  45.                 i++;
  46.                 k++;
  47.             }
  48.             else
  49.             {
  50.                 if (b[j]%2==0)
  51.                 {
  52.                     c[k]=b[j];
  53.                     j--;
  54.                     k++;
  55.                 }
  56.                 else
  57.                 {
  58.                     i++;
  59.                     j--;
  60.                 }
  61.             }
  62.         }
  63.     }
  64.     while (j>=0)
  65.     {
  66.         if (b[j]%2==0)
  67.         {
  68.             c[k]=b[j];
  69.             k++;
  70.         }
  71.         j--;
  72.     }
  73.     while (i<n)
  74.     {
  75.         if (a[i]%2==0)
  76.         {
  77.             c[k]=a[i];
  78.             k++;
  79.         }
  80.         i++;
  81.     }
  82.     for (int i=0;i<k;i++)
  83.     {
  84.         cout<<c[i]<<" ";
  85.     }
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement