Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int** test(int* tab, int n);
- int main() {
- int t[] = {3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3};
- int** result = test(t, sizeof(t)/sizeof(*t));
- for(int x = 0; x < 2; ++x) {
- for(int y = 0; y < result[x][0] + 1; ++y) {
- cout << result[x][y] << " ";
- }
- cout << endl;
- }
- }
- int** test(int* tab, int n) {
- int dz_size = 8;
- int pa_size = 8;
- int* dz = (int*) malloc(sizeof(int) * dz_size);
- int* pa = (int*) malloc(sizeof(int) * pa_size);
- for(int x = 0; x < n; ++x) {
- if(n % tab[x] == 0) {
- if(dz[0] >= dz_size - 1) {
- dz_size *= 2;
- dz = (int*) realloc(dz, sizeof(int) * dz_size);
- }
- dz[(dz[0]++) + 1] = tab[x];
- }
- if(tab[x] % 2 == 0) {
- if(pa[0] >= pa_size - 1) {
- pa_size *= 2;
- pa = (int*) realloc(pa, sizeof(int) * pa_size * 2);
- }
- pa[(pa[0]++) + 1] = tab[x];
- }
- }
- int** link = new int*[2];
- link[0] = dz;
- link[1] = pa;
- free(dz);
- free(pa);
- return link;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement