Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <mem.h> //для функции calloc
- #define bool _Bool
- #define true 1
- #define false 0
- int arrayEquals(int *arr1, int *arr2, int size) {
- int *compare = malloc(sizeof(int) * size); //compare - копия первого массива, чтобы его не менять
- //memcpy(compare, arr1, size * sizeof(int)); //копируем arr1 в compare
- for (int l = 0; l < size; l++) {
- compare[l] = arr1[l];
- }
- for (int i = 0; i < size; ++i) {
- int found = 0;
- for (int j = 0; j < size; ++j) {
- //if (compare[j] == -1) continue;
- if (compare[j] != arr2[i]) {
- continue;
- }
- compare[j] = -1;
- found = 1;
- break;
- }
- if (found && i == size - 1)return 1;
- if (!found) return 0;
- }
- /*printf("nnn");
- for (int k = 0; k < size; ++k) {
- if (compare[k] != -1) {
- return 0; //проверка, остались ли не удаленные элементы, если остались, то столбцы не равны
- }
- }
- return 1;*/
- }
- int main() {
- int i, j, l;
- int lines;
- int columns;
- printf("Enter number of lines");
- scanf("%d", &lines);
- printf("Enter number of columns");
- scanf("%d", &columns);
- int arr[lines][columns];
- srand(time(0));
- for (i = 0; i < lines; i++) {
- for (j = 0; j < columns; j++) {
- arr[i][j] = rand() % 5;
- printf("%d ", arr[i][j]);
- }
- printf("\n");
- }
- //Getting last column
- int *arr_last_column = malloc(sizeof(int) * lines);
- for (l = 0; l < lines; l++) {
- arr_last_column[l] = arr[l][columns - 1];
- //printf("%d", arr_last_column[l]);
- }//
- printf("\n\n\n");
- int *next_column = malloc(sizeof(int) * lines);
- for (i = 0; i < columns - 1; ++i) {
- for (int m = 0; m < lines; ++m) {
- next_column[m] = arr[m][i]; //записываем в массив все столбцы, кроме последнего. i - столбец, m - линия
- }
- if (arrayEquals(next_column, arr_last_column, lines)) {
- printf("Column %d equals to the last\n", i);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement