Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- int n;
- ifstream f("input.txt", ios::in);
- void print(int** a){
- for (int i = 0; i < n; i++){
- for (int j = 0; j < n; j++){
- cout << a[i][j] << " ";
- }
- cout << endl;
- }
- }
- void swap(int** &a, int i,int j){
- int c;
- for (int q = 0; q < n; q++){
- c = a[i][q];
- a[i][q] = a[j][q];
- a[j][q] = c;
- }
- for (int q = 0; q < n; q++){
- c = a[q][i];
- a[q][i] = a[q][j];
- a[q][j] = c;
- }
- }
- bool Scan(int** a, int** b){
- bool q = true;
- for (int i = 0; i < n && q; i++){
- for (int j = 0; j < n; j++){
- if (a[i][j] != b[i][j]) q = false;
- }
- }
- return q;
- }
- void main(){
- bool p = false;
- f >> n;
- int** a = new int*[n];
- int** b = new int*[n];
- for (int i = 0; i < n; i++){
- a[i] = new int[n];
- for (int j = 0; j < n; j++){
- f >> a[i][j];
- }
- }
- for (int i = 0; i < n; i++){
- b[i] = new int[n];
- for (int j = 0; j < n; j++){
- f >> b[i][j];
- }
- }
- p = Scan(a, b);
- if (p == false){
- for (int g = 0; g < n && p == false; g++){
- for (int i = 0; i < n && p == false; i++){
- for (int j = 0; j < n && p == false; j++){
- swap(b, i, j);
- p = Scan(a, b);
- }
- }
- swap(b, 0, g);
- }
- }
- if (p) cout << "IZOMORF" << endl;
- else cout << "No!" << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment