第四题:
int helper(int i, int j, int x, int y, int k, vector<vector<char>> &graph) {
for (int a = 0; a < k; a++) {
for (int b = 0; b < k; b++) {
if (graph[i + a][j + b] != graph[x + a][y + b]) {
k = min(k, b);
}
}
}
return k;
}
int main() {
int n, m;
cin >> n >> m;
vector<vector<char>> graph(n, vector<char>(m));
vector<vector<pair<int, int>>> hash(26);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> graph[i][j];
hash[graph[i][j] - 'a'].push_back(make_pair(i, j));
}
}
int i, j, x, y, k, temp;
int res = 0;
vector<int> re(4);
for (int t = 0; t < 26; t++) {
for (int a = 0; a < hash[t].size(); a++) {
for (int b = a + 1; b < hash[t].size(); b++) {
i = hash[t][a].first;
j = hash[t][a].second;
x = hash[t][b].first;
y = hash[t][b].second;
k = min(min(n - i, m - j), min(n - x, m - y));
temp = helper(i, j, x, y, k, graph);
if (temp > res) {
res = temp;
re[0] = i;
re[1] = j;
re[2] = x;
re[3] = y;
}
}
}
}
if (res != 0) {
cout << res << endl;
cout << re[0] + 1 << ' ' << re[1] + 1 << endl;
cout << re[2] + 1 << ' ' << re[3] + 1 << endl;
}
else
cout << 0 << endl;
system("pause");
return 0;
}