Advertisement
Guest User

Untitled

a guest
May 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int** test(int* tab, int n);
  6.  
  7. int main() {
  8.     int t[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3};
  9.     int** result = test(t, sizeof(t)/sizeof(*t));
  10.     for(int x = 0; x < 2; ++x) {
  11.         for(int y = 0; y < result[x][0] + 1; ++y) {
  12.             cout << result[x][y] << " ";
  13.         }
  14.         cout << endl;
  15.     }
  16. }
  17.  
  18. int** test(int* tab, int n) {
  19.     int dz_size = 8;
  20.     int pa_size = 8;
  21.  
  22.     int* dz = (int*) malloc(sizeof(int) * dz_size);
  23.     int* pa = (int*) malloc(sizeof(int) * pa_size);
  24.  
  25.     for(int x = 0; x < n; ++x) {
  26.  
  27.         if(n % tab[x] == 0) {
  28.             if(dz[0] >= dz_size - 1) {
  29.                 dz_size *= 2;
  30.                 dz = (int*) realloc(dz, sizeof(int) * dz_size);
  31.             }
  32.             dz[(dz[0]++) + 1] = tab[x];
  33.         }
  34.  
  35.         if(tab[x] % 2 == 0) {
  36.             if(pa[0] >= pa_size - 1) {
  37.                 pa_size *= 2;
  38.                 pa = (int*) realloc(pa, sizeof(int) * pa_size * 2);
  39.             }
  40.             pa[(pa[0]++) + 1] = tab[x];
  41.         }
  42.     }
  43.  
  44.     int** link = new int*[2];
  45.     link[0] = dz;
  46.     link[1] = pa;
  47.  
  48.     free(dz);
  49.     free(pa);
  50.  
  51.     return link;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement