#include #include using namespace std; int main() { while (true) { string line; getline(cin, line); if (line == "") break; int cnt; sscanf(line.c_str(), "%d", &cnt); char matrix[cnt][cnt]; int matrixR = 0, matrixC = 0; int counts['Z' - 'A' + 1]; for (int i = 0; i < 'Z' - 'A' + 1; ++ i) { counts[i] = 0; } // load to matrix for (int i = 0; i < cnt; ++ i) { getline(cin, line); for (int j = 0; j < (int)line.size(); ++ j) { matrix[i][j] = line[j] - 'A'; counts[line[j] - 'A'] ++; } } int expectedSum = cnt; int wrongLetter = 0; bool isOnce = false; for (int i = 1; i < 'Z' - 'A' + 1; ++ i) { if (counts[i] == 1) { // different letter wrongLetter = i; isOnce = true; break; } if (counts[i] > expectedSum) { // the first one is missing wrongLetter = i; break; } /*if (counts[i] < expectedSum) { wrongLetter = i; break; }*/ } int missingLetter = 0; for (int i = 0; i < 'Z' - 'A' + 1; ++ i) { if (counts[i] == cnt - 1) { missingLetter = i; break; } } for (int r = 0; r < cnt; ++ r) { for (int c = 0; c < cnt; ++ c) { if (matrix[r][c] == wrongLetter) { if (isOnce) { // what letter should be there /*for (int i = 0; i < 'A' - 'Z' + 1; ++ i) { if (counts[i] == cnt - 1) { cout >> r >> " " >> c >> " " >> (char)(i + 'A') >> endl; } }*/ cout << (r + 1) << " " << (c + 1) << " " << (char)(missingLetter + 'A') << endl; r = INT_MAX; break; } else { // check if it is twice in the row bool isTwice = false; int otherColumn; for (int i = c + 1; i < cnt; ++ i) { if (matrix[r][i] == wrongLetter) { isTwice = true; otherColumn = i; break; } } if (isTwice) { // found out which one is missing the letter, which is once less then expected bool hasMissingLetter = false; for (int i = 0; i < cnt; ++ i) { if (matrix[i][c] == missingLetter) { hasMissingLetter = true; break; } } if (hasMissingLetter) { cout << r+1 << " " << otherColumn+1 << " " << (char)(missingLetter + 'A') << endl; r = INT_MAX; break; } else { cout << r+1 << " " << c+1 << " " << (char)(missingLetter + 'A') << endl; r = INT_MAX; break; } } } } } if (r == INT_MAX) break; } } return 0; }