#include #include using namespace std; typedef struct person { uint32_t row; uint32_t column; char letter; } Person; void rozdilny(vector & persons, int * pole, int n) { int pismenoN = -1, pismenoT = -1; for (int i = 0; i < 26;++i) { if (pole[i] == 0) continue; if (pole[i] == 1) pismenoN = i; if (pole[i] == n - 1) pismenoT = i; } for (const auto & person : persons) { if (((int)person->letter) - 65 == pismenoN) { cout << (person->row + 1) << " " << (person->column + 1) << " " << (char)(pismenoT + 65) << endl; break; } } } Person *** matrix; int stejny(vector & persons, int * pole, int n) { char wrong, right; for (int i = 0; i < 26;++i) { if (pole[i] == 0) continue; if (pole[i] == n + 1) wrong = (char)(i + 65); if (pole[i] == n - 1) right = (char)(i + 65); } int radek = -1; int column1 = -1; int column2 = -1; for (int i = 0; i < n; ++i) { int column = -1; for (int j = 0; j < n; ++j) { if (wrong == matrix[i][j]->letter) { if (column == -1) column = j; else { column1 = column; column2 = j; radek = i; break; } } } if (column1 != -1) break; } int jetam = 0; for (int i = 0; i < n; ++i) { if (wrong == matrix[i][column1]->letter) { jetam++; if (jetam == 2) { cout << (matrix[radek][column1]->row + 1) << " " << (matrix[radek][column1]->column + 1) << " " << right << endl; return 0; } } } jetam = 0; for (int i = 0; i < n; ++i) { if (wrong == matrix[i][column2]->letter) { jetam++; if (jetam == 2) { cout << (matrix[radek][column2]->row + 1) << " " << (matrix[radek][column2]->column + 1) << " " << right << endl; return 0; } } } } int main(int argc, char ** argv) { int n; while(cin >> n) { int pole[26]{0}; int jednicka = 0; vector persons; matrix = new Person**[n]; for (int i = 0; i < n; ++i) matrix[i] = new Person*[n]; for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { Person * temp = new Person(); cin >> temp->letter; temp->row = i; temp->column = j; pole[((int)temp->letter) - 65]++; if (pole[((int)temp->letter) - 65] == 1) jednicka++; if (pole[((int)temp->letter) - 65] == 2) jednicka--; persons.push_back(temp); matrix[i][j] = temp; } } if (jednicka == 1) rozdilny(persons, pole, n); else stejny(persons, pole, n); for (int i = 0; i < n; ++i) delete[] matrix[i]; delete[] matrix; } return 0; }