SHARE
TWEET

Untitled

a guest Jan 15th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3. void resize(int& n,int*newArr) {
  4.     int newSize = n+1;
  5.     int* newArr1 = new int[newSize];
  6.  
  7.     memcpy(newArr1, newArr, n * sizeof(int));
  8.  
  9.     n = newSize;
  10.     delete[] newArr;
  11.     newArr = newArr1;
  12. }
  13. int main() {
  14.     int n, m;
  15.     cin >> n;
  16.     int initialN = n;
  17.     int* arr = new int[n];
  18.     bool toAdd = true;
  19.     for (int i = 0; i < n; i++)
  20.     {
  21.         cin >> arr[i];
  22.     }
  23.     cin >> m;
  24.     int* arr1 = new int[m];
  25.     for (int i = 0; i < m; i++)
  26.     {
  27.         cin >> arr1[i];
  28.     }
  29.     int* newArr = new int[n];
  30.     for (int i = 0; i < n; i++)
  31.     {
  32.         newArr[i] = arr[i];
  33.     }
  34.     //dotuk vs 6
  35.    
  36.     for (int i = 0; i < m; i++)
  37.     {
  38.         for (int j = 0; j < initialN; j++)
  39.         {
  40.             if (arr1[i]%arr[j]==0)
  41.             {
  42.                 toAdd = false;
  43.                
  44.             }
  45.         }
  46.         if (toAdd)
  47.         {
  48.            
  49.            
  50.             int newSize = n + 1;
  51.             int* newArr1 = new int[newSize];
  52.  
  53.             memcpy(newArr1, newArr, n * sizeof(int));
  54.  
  55.             n = newSize;
  56.             delete[] newArr;
  57.             newArr = newArr1;
  58.             //vmesto tiq raboti trqbva da e resize ama ne stava
  59.             newArr[n - 1] = arr1[i];
  60.            
  61.         }
  62.         toAdd = true;
  63.        
  64.     }
  65.     for (int i = 0; i < n; i++)
  66.     {
  67.         cout << newArr[i] << ' ';
  68.     }
  69.    
  70.     delete[]arr;
  71.     delete[]arr1;
  72.     delete[]newArr;
  73.     return 0;
  74. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top