Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<string> readPhoto()
- {
- int n, m;
- cin >> n >> m;
- vector<string> result(n);
- for(int i = 0; i < n; i++)
- cin >> result[i];
- return result;
- }
- vector<string> cut(vector<string> f)
- {
- int minx = INT_MAX;
- int maxx = INT_MIN;
- int miny = INT_MAX;
- int maxy = INT_MIN;
- for(int i = 0; i < f.size(); i++)
- for(int j = 0; j < f[0].length(); j++)
- {
- if (f[i][j] == '*')
- {
- minx = min(minx, i);
- maxx = max(maxx, i);
- miny = min(miny, j);
- maxy = max(maxy, j);
- }
- }
- if (minx <= maxx)
- {
- vector<string> result(maxx - minx + 1, string(maxy - miny + 1, '?'));
- for(int i = 0; i < maxx - minx + 1; i++)
- for(int j = 0; j < maxy - miny + 1; j++)
- result[i][j] = f[i + minx][j + miny];
- return result;
- }
- else
- return vector<string> ();
- }
- vector<string> rotate(vector<string> f)
- {
- if (f.empty())
- return f;
- vector<string> result(f[0].length(), string(f.size(), '?'));
- for(int i = 0; i < f.size(); i++)
- for(int j = 0; j < f[0].length(); j++)
- result[f[0].length() - j - 1][i] = f[i][j]; //clockwise
- return result;
- }
- vector<string> canonise(vector<string> f)
- {
- f = cut(f);
- vector<string> result = f;
- for(int i = 0; i < 3; i++)
- {
- f = rotate(f);
- result = min(result, f);
- }
- return result;
- }
- int main()
- {
- vector<string> a = readPhoto();
- vector<string> b = readPhoto();
- if (canonise(a) == canonise(b))
- cout << "YES\n";
- else
- cout << "NO\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement