Advertisement
SergeyPGUTI

6.3.10

Nov 21st, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. void Insertion(int a[],int n,int b[],int m)
  6. {
  7.     int * A=new int [n];
  8.     int k=1;
  9.   for (int PosA=0,PosB=0;PosA<n && PosB<m;)
  10.   {
  11.       if (PosA<n && a[PosA]<b[PosB]) PosA++;
  12.        else  if (PosB<m && a[PosA]>b[PosB]) PosB++;
  13.         else if (PosB<m && PosA<n && a[PosA]==b[PosB]) {A[k]=a[PosA];PosA++; PosB++;k++;}
  14.   }
  15.  
  16.     for (int j=1;j<k;j++)
  17.     {
  18.         if ( A[j]!=A[j-1]) cout<<A[j]<<" ";
  19.     }
  20. }
  21.  
  22. int main()
  23. {
  24.     int n,m;
  25.     cin>>n;
  26.     int * A=new int [n];
  27.     for (int i=0;i<n;i++)
  28.     {
  29.         cin>>A[i];
  30.     }
  31.     cin>>m;
  32.     int * B=new int [m];
  33.     for (int i=0;i<m;i++)
  34.     {
  35.         cin>>B[i];
  36.     }
  37.     Insertion(A,n,B,m);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement