Advertisement
_rashed

UVA 466 Mirror, Mirror

Oct 10th, 2021 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7.  
  8. class pattern {
  9. public:
  10.     int n;
  11.     char arr[10][10];
  12.     pattern(int n, char arr[10][10]) {
  13.         this->n = n;
  14.         for(int i = 0; i < n; i++) {
  15.             for(int j = 0; j < n; j++) {
  16.                 this->arr[i][j] = arr[i][j];
  17.             }
  18.         }
  19.     }
  20.  
  21.     bool operator == (const pattern &p) const {
  22.         for(int i = 0; i < n; i++) {
  23.             for(int j = 0; j < n; j++) {
  24.                 if(arr[i][j] != p.arr[i][j]) {
  25.                     return false;
  26.                 }
  27.             }
  28.         }
  29.         return true;
  30.     }
  31.  
  32.     void rotate_90() {
  33.         char new_arr[10][10];
  34.         for(int col = 0; col < n; col++) {
  35.             for(int row = n-1; row >= 0; row--) {
  36.                 new_arr[col][n-1-row] = arr[row][col];
  37.             }
  38.         }
  39.         for(int i = 0; i < n; i++) {
  40.             for(int j = 0; j < n; j++) {
  41.                 arr[i][j] = new_arr[i][j];
  42.             }
  43.         }
  44.     }
  45.  
  46.     void reflect() {
  47.         for(int row = 0; 2*row < n; row++) {
  48.             for(int col = 0; col < n; col++) {
  49.                 swap(arr[row][col],arr[n-row-1][col]);
  50.             }
  51.         }
  52.     }
  53. };
  54.  
  55. int main()
  56. {
  57.     ios_base::sync_with_stdio(false);
  58.     cin.tie(NULL);
  59.     cout.tie(NULL);
  60.     int n;
  61.     int ti = 1;
  62.     while(cin >> n) {
  63.         char arr1[10][10];
  64.         char arr2[10][10];
  65.         for(int i = 0; i < n; i++) {
  66.             for(int j = 0; j < n; j++) {
  67.                 cin >> arr1[i][j];
  68.             }
  69.             for(int j = 0; j < n; j++) {
  70.                 cin >> arr2[i][j];
  71.             }
  72.         }
  73.         pattern p1 = pattern(n,arr1);
  74.         pattern p2 = pattern(n,arr2);
  75.         if(p1 == p2) {
  76.             cout << "Pattern " << ti++ << " was preserved.\n";
  77.             continue;
  78.         }
  79.         for(int i = 90; i < 360; i += 90) {
  80.             p1.rotate_90();
  81.             if(p1 == p2) {
  82.                 cout << "Pattern " << ti++ << " was rotated " << i << " degrees.\n";
  83.                 break;
  84.             }
  85.         }
  86.         if(p1 == p2) {
  87.             continue;
  88.         }
  89.         p1.rotate_90();
  90.         p1.reflect();
  91.         if(p1 == p2) {
  92.             cout << "Pattern " << ti++ << " was reflected vertically.\n";
  93.             continue;
  94.         }
  95.         for(int i = 90; i < 360; i += 90) {
  96.             p1.rotate_90();
  97.             if(p1 == p2) {
  98.                 cout << "Pattern " << ti++ << " was reflected vertically and rotated " << i << " degrees.\n";
  99.                 break;
  100.             }
  101.         }
  102.         if(p1 == p2) {
  103.             continue;
  104.         }
  105.         cout << "Pattern " << ti++ << " was improperly transformed.\n";
  106.     }
  107.     return 0;
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement