awdawawd

Kolorwanie:
Status:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
#include <iostream>
#include <time.h>
#include <algorithm>

using namespace std;

void perm_count(int ** arr2d, int n, int m, int * arr) {

    int** copyarr2 = new int*[n];
    for (int i = 0; i < n; i++)
    {
        copyarr2[i] = new int[m];
        for (int j = 0; j < m; j++) {
            copyarr2[i][j] = arr2d[i][j];
        }
    }

    sort(arr, arr + m);
    for (int i = 0; i < n; i++) {
        sort(arr2d[i], arr2d[i] + m);
    }

    int counter = 0;
    bool check = true;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m && check; j++) {
            if(arr2d[i][j] != arr[j]) {
                check = false;
            }
        }
        if(check) {
            counter++;
            for (int j = 0; j < m; j++)
            {
                cout << copyarr2[i][j] << " ";
            }
            cout << endl;
        }
        check = true;
    }
}

int main() {

    int n, m;
    cin >> n >> m;

    int* arr = new int[m];
    int** arr2d = new int*[n];

    srand(time(NULL));

    for (int i = 0; i < n; i++) {
        arr2d[i] = new int[m];
        for (int j = 0; j < m; j++) {
            arr2d[i][j] = rand() % 11 - 5;
            cout << arr2d[i][j] << " ";
        }
        std::cout << '\n';
    }

    cout << "arr:" << endl;
    for (int i = 0; i < m; i++) {
        arr[i] = rand() % 11 - 5;
        cout << arr[i] << ' ';
    }

    cout << endl << "wyjsice:" << endl;
    perm_count(arr2d, n, m, arr);

    for (int i = 0; i < n; i++) {
        delete[] arr2d[i];
    }

    delete[] arr2d;
    delete[] arr;
    return 0;
}

Copyrights 2014-2021 © Wklejaj.pl Wszelkie prawa zastrzeżone.