Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <map>
- #include <vector>
- #include <algorithm>
- using namespace std;
- int main() {
- int m;
- cin >> m;
- vector<vector<int> > a(m, vector<int>(m));
- for (int i = 0; i < m; i++) {
- for (int j = 0; j < m; j++) {
- cin >> a[i][j];
- }
- }
- bool ass = 1;
- for (int i = 0; i < m && ass; i++) {
- for (int j = i + 1; j < m && ass; j++) {
- for (int q = j + 1; q < m && ass; q++) {
- if (a[i][a[j][q]] != a[a[i][j]][q]) {
- ass = 0;
- }
- if (a[j][a[q][i]] != a[a[j][q]][i]) {
- ass = 0;
- }
- if (a[q][a[i][j]] != a[a[q][i]][j]) {
- ass = 0;
- }
- if (a[i][a[q][j]] != a[a[i][q]][j]) {
- ass = 0;
- }
- if (a[j][a[i][q]] != a[a[j][i]][q]) {
- ass = 0;
- }
- if (a[q][a[j][i]] != a[a[q][j]][i]) {
- ass = 0;
- }
- }
- }
- }
- bool ed = 0;
- bool ned = -1;
- for (int i = 0; i < m; i++) {
- bool e = 1;
- for (int j = 0; j < m; j++) {
- if (a[i][j] != a[j][i] || a[j][i] != j + 1) {
- e = 0;
- break;
- }
- }
- if (e) {
- ed = 1;
- ned = i + 1;
- break;
- }
- }
- bool komp = 1;
- for (int i =0; i < m && komp; i++){
- for (int j = 0; j < m && komp; j++) {
- if (a[i][j] != a[j][i]) {
- komp = 0;
- }
- }
- }
- bool obr = 0;
- if (ed) {
- int k = 0;
- for (int i = 0; i < m; i++) {
- bool e = 0;
- for (int j = 0; j < m; j++) {
- if (a[i][j] == a[j][i] && a[i][j] == ned) {
- e = 1;
- }
- }
- if (e) {
- k++;
- }
- }
- if (k == m) {
- obr = 1;
- }
- }
- if (ass) {
- if (komp) {
- if (ed) {
- if (obr) {
- cout << "abelian group";
- }
- else {
- cout << "commutative monoid";
- }
- }
- else {
- cout << "commutative semigroup";
- }
- }
- else {
- if (ed) {
- if (obr) {
- cout << "group";
- }
- else {
- cout << "monoid";
- }
- }
- else {
- cout << "semigroup";
- }
- }
- }
- else {
- if (komp) {
- cout << "commutative groupoid";
- }
- else {
- cout << "groupoid";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement