Advertisement
Guest User

Untitled

a guest
Aug 14th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <iostream>
  2. bool isSubset(int* set1, int* set2, const size_t rows)
  3. {
  4. for (size_t i = 0; i < rows; i++)
  5. {
  6. double curr = set2[i];
  7. for (size_t j = 0; j < rows; j++)
  8. {
  9. if (curr == set1[j])
  10. {
  11. break;
  12. }
  13. else if (j == rows - 1)
  14. {
  15. return false;
  16. }
  17. }
  18. }
  19. return true;
  20. }
  21. int main()
  22. {
  23. const size_t rows = 5;
  24. const size_t cols = 6;
  25. int matrix[][cols] = { 1,2,3,4,5,1,
  26. 2,3,4,5,6,1,
  27. 2,5,6,0,2,3,
  28. 2,3,5,7,3,1,
  29. 3,4,6,7,8,2 };
  30. for (size_t i = 0; i < cols; i++)
  31. {
  32. std::cout << "alike column numbers to column "<< i+1<<" are: ";
  33. int currSet[rows];
  34. for (size_t j = 0; j < rows; j++)
  35. {
  36. currSet[j] = matrix[j][i];
  37. }
  38. for (size_t k = 0; k < cols; k++)
  39. {
  40. int setToCheck[rows];
  41. for (size_t l = 0; l < rows; l++)
  42. {
  43. setToCheck[l] = matrix[l][k];
  44. }
  45. if (i != k && isSubset(currSet, setToCheck, rows) && isSubset(setToCheck, currSet, rows))
  46. {
  47. std::cout << k+1 << ' ';
  48. }
  49. }
  50. std::cout << std::endl;
  51. }
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement