ChameL1oN

Hz

Mar 25th, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. int n;
  9. ifstream f("input.txt", ios::in);
  10.  
  11. void print(int** a){
  12. for (int i = 0; i < n; i++){
  13. for (int j = 0; j < n; j++){
  14. cout << a[i][j] << " ";
  15. }
  16. cout << endl;
  17. }
  18. }
  19.  
  20. void swap(int** &a, int i,int j){
  21. int c;
  22.  
  23. for (int q = 0; q < n; q++){
  24. c = a[i][q];
  25. a[i][q] = a[j][q];
  26. a[j][q] = c;
  27. }
  28. for (int q = 0; q < n; q++){
  29. c = a[q][i];
  30. a[q][i] = a[q][j];
  31. a[q][j] = c;
  32. }
  33.  
  34. }
  35.  
  36. bool Scan(int** a, int** b){
  37. bool q = true;
  38. for (int i = 0; i < n && q; i++){
  39. for (int j = 0; j < n; j++){
  40. if (a[i][j] != b[i][j]) q = false;
  41. }
  42. }
  43. return q;
  44. }
  45.  
  46.  
  47.  
  48. void main(){
  49. bool p = false;
  50. f >> n;
  51. int** a = new int*[n];
  52. int** b = new int*[n];
  53. for (int i = 0; i < n; i++){
  54. a[i] = new int[n];
  55. for (int j = 0; j < n; j++){
  56. f >> a[i][j];
  57. }
  58. }
  59. for (int i = 0; i < n; i++){
  60. b[i] = new int[n];
  61. for (int j = 0; j < n; j++){
  62. f >> b[i][j];
  63. }
  64. }
  65. p = Scan(a, b);
  66. if (p == false){
  67. for (int g = 0; g < n && p == false; g++){
  68. for (int i = 0; i < n && p == false; i++){
  69. for (int j = 0; j < n && p == false; j++){
  70. swap(b, i, j);
  71. p = Scan(a, b);
  72.  
  73. }
  74. }
  75. swap(b, 0, g);
  76. }
  77. }
  78. if (p) cout << "IZOMORF" << endl;
  79. else cout << "No!" << endl;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment