Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4. #include <mem.h> //для функции calloc
  5.  
  6. #define bool _Bool
  7. #define true 1
  8. #define false 0
  9.  
  10. int arrayEquals(int *arr1, int *arr2, int size) {
  11. int *compare = malloc(sizeof(int) * size); //compare - копия первого массива, чтобы его не менять
  12. //memcpy(compare, arr1, size * sizeof(int)); //копируем arr1 в compare
  13. for (int l = 0; l < size; l++) {
  14. compare[l] = arr1[l];
  15. }
  16. for (int i = 0; i < size; ++i) {
  17. int found = 0;
  18. for (int j = 0; j < size; ++j) {
  19. //if (compare[j] == -1) continue;
  20. if (compare[j] != arr2[i]) {
  21. continue;
  22. }
  23. compare[j] = -1;
  24. found = 1;
  25. break;
  26. }
  27. if (found && i == size - 1)return 1;
  28. if (!found) return 0;
  29. }
  30. /*printf("nnn");
  31. for (int k = 0; k < size; ++k) {
  32. if (compare[k] != -1) {
  33. return 0; //проверка, остались ли не удаленные элементы, если остались, то столбцы не равны
  34. }
  35. }
  36. return 1;*/
  37. }
  38.  
  39. int main() {
  40. int i, j, l;
  41. int lines;
  42. int columns;
  43.  
  44. printf("Enter number of lines");
  45. scanf("%d", &lines);
  46. printf("Enter number of columns");
  47. scanf("%d", &columns);
  48.  
  49. int arr[lines][columns];
  50.  
  51. srand(time(0));
  52. for (i = 0; i < lines; i++) {
  53. for (j = 0; j < columns; j++) {
  54. arr[i][j] = rand() % 5;
  55. printf("%d ", arr[i][j]);
  56. }
  57. printf("\n");
  58. }
  59. //Getting last column
  60. int *arr_last_column = malloc(sizeof(int) * lines);
  61.  
  62. for (l = 0; l < lines; l++) {
  63. arr_last_column[l] = arr[l][columns - 1];
  64. //printf("%d", arr_last_column[l]);
  65. }//
  66. printf("\n\n\n");
  67.  
  68. int *next_column = malloc(sizeof(int) * lines);
  69. for (i = 0; i < columns - 1; ++i) {
  70. for (int m = 0; m < lines; ++m) {
  71. next_column[m] = arr[m][i]; //записываем в массив все столбцы, кроме последнего. i - столбец, m - линия
  72. }
  73. if (arrayEquals(next_column, arr_last_column, lines)) {
  74. printf("Column %d equals to the last\n", i);
  75. }
  76. }
  77.  
  78. return 0;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement