Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <array>
- using namespace std;
- /* *1 | 0 1 2 *2 | a b
- ---+------- ---+-----
- 0 | 0 1 2 a | a b
- 1 | 1 2 0 b | b a
- 2 | 2 0 1
- */
- struct coord {
- int a;
- char b;
- };
- int op1 (int a, int b);
- char op2 (char a, char b);
- coord op12 (coord a, coord b);
- bool comprobar_asociatividad(array<coord,6> arr2);
- void verificar_simetria (array<array<coord,6>,6>& a);
- int main()
- {
- array<array<coord,6>,6> arr1;
- array<coord,6> arr2 = {0,'a',0,'b',1,'a',1,'b',2,'a',2,'b'};
- for (int i=0; i<6; i++) //fills and prints matrix
- {
- for (int j=0; j<6; j++)
- {
- arr1.at(i).at(j) = op12(arr2.at(i),arr2.at(j));
- cout << arr1.at(i).at(j).a << arr1.at(i).at(j).b << ' ';
- }
- cout << endl;
- }
- cout << endl;
- verificar_simetria(arr1);
- if (comprobar_asociatividad(arr2))
- cout << "Asociativa: si" << endl << endl;
- else
- cout << "Asociativa: no" << endl << endl;
- return 0;
- }
- void verificar_simetria (array<array<coord,6>,6>& a)
- {
- for (int i=0; i<6; i++)
- for (int j=0; j<6; j++)
- if (a.at(i).at(j).a != a.at(j).at(i).a or a.at(i).at(j).b != a.at(j).at(i).b)
- {
- cout << "Simetrica: no\n";
- return;
- }
- cout << "Simetrica: si\n";
- }
- bool comprobar_asociatividad(array<coord,6> arr2)
- {
- coord miembro1, miembro2;
- for (int i=0; i<6; i++)
- for (int j=0; j<6; j++)
- for (int k=0; k<6; k++)
- {
- miembro1 = op12(arr2.at(i),op12(arr2.at(j),arr2.at(k)));
- miembro2 = op12(op12(arr2.at(i),arr2.at(j)),arr2.at(k));
- if (miembro1.a != miembro2.a or miembro1.b != miembro2.b)
- return false;
- }
- return true;
- }
- coord op12 (coord p, coord r)
- {
- return {op1(p.a,r.a),op2(p.b,r.b)};
- }
- int op1 (int a, int b)
- {
- return (a+b)%3;
- }
- char op2 (char a, char b)
- {
- if(a=='a' and b=='a' or a=='b' and b=='b')
- return 'a';
- if(a=='a' and b=='b' or a=='b' and b=='a')
- return 'b';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement