Advertisement
anon20016

F

Oct 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <map>
  4. #include <vector>
  5. #include <algorithm>
  6.  
  7. using namespace std;
  8.  
  9.  
  10. int main() {
  11. int m;
  12. cin >> m;
  13. vector<vector<int> > a(m, vector<int>(m));
  14. for (int i = 0; i < m; i++) {
  15. for (int j = 0; j < m; j++) {
  16. cin >> a[i][j];
  17. }
  18. }
  19. bool ass = 1;
  20. for (int i = 0; i < m && ass; i++) {
  21. for (int j = i + 1; j < m && ass; j++) {
  22. for (int q = j + 1; q < m && ass; q++) {
  23. if (a[i][a[j][q]] != a[a[i][j]][q]) {
  24. ass = 0;
  25. }
  26. if (a[j][a[q][i]] != a[a[j][q]][i]) {
  27. ass = 0;
  28. }
  29. if (a[q][a[i][j]] != a[a[q][i]][j]) {
  30. ass = 0;
  31. }
  32.  
  33. if (a[i][a[q][j]] != a[a[i][q]][j]) {
  34. ass = 0;
  35. }
  36. if (a[j][a[i][q]] != a[a[j][i]][q]) {
  37. ass = 0;
  38. }
  39. if (a[q][a[j][i]] != a[a[q][j]][i]) {
  40. ass = 0;
  41. }
  42. }
  43. }
  44. }
  45.  
  46. bool ed = 0;
  47. bool ned = -1;
  48. for (int i = 0; i < m; i++) {
  49. bool e = 1;
  50. for (int j = 0; j < m; j++) {
  51. if (a[i][j] != a[j][i] || a[j][i] != j + 1) {
  52. e = 0;
  53. break;
  54. }
  55. }
  56. if (e) {
  57. ed = 1;
  58. ned = i + 1;
  59. break;
  60. }
  61. }
  62.  
  63. bool komp = 1;
  64. for (int i =0; i < m && komp; i++){
  65. for (int j = 0; j < m && komp; j++) {
  66. if (a[i][j] != a[j][i]) {
  67. komp = 0;
  68. }
  69. }
  70. }
  71.  
  72. bool obr = 0;
  73. if (ed) {
  74. int k = 0;
  75. for (int i = 0; i < m; i++) {
  76. bool e = 0;
  77. for (int j = 0; j < m; j++) {
  78. if (a[i][j] == a[j][i] && a[i][j] == ned) {
  79. e = 1;
  80. }
  81. }
  82. if (e) {
  83. k++;
  84. }
  85. }
  86. if (k == m) {
  87. obr = 1;
  88. }
  89. }
  90.  
  91. if (ass) {
  92. if (komp) {
  93. if (ed) {
  94. if (obr) {
  95. cout << "abelian group";
  96. }
  97. else {
  98. cout << "commutative monoid";
  99. }
  100. }
  101. else {
  102. cout << "commutative semigroup";
  103. }
  104. }
  105. else {
  106. if (ed) {
  107. if (obr) {
  108. cout << "group";
  109. }
  110. else {
  111. cout << "monoid";
  112. }
  113. }
  114. else {
  115. cout << "semigroup";
  116. }
  117. }
  118. }
  119. else {
  120. if (komp) {
  121. cout << "commutative groupoid";
  122. }
  123. else {
  124. cout << "groupoid";
  125. }
  126. }
  127.  
  128. return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement