/* * File: tribune.cpp * Author: cteam003 * * Created on October 22, 2016, 11:36 AM */ #include #include #include #include #include #include #include using namespace std; /* * */ int main(int argc, char** argv) { int numlines; while (cin >> numlines){ string tmp; vector > grid (numlines, vector(numlines)); for (int i = 0; i < numlines; i++){ cin >> tmp; for (int j = 0; j < numlines; j++) grid[i][j] = tmp[j]; } set s1, s2, s3, teams; for (int i = 0; i < numlines; i++) { s1.insert(grid[0][i]); s2.insert(grid[1][i]); s3.insert(grid[2][i]); } auto it1 = s1.begin(); auto it2 = s2.begin(); auto it3 = s3.begin(); bool flag = true; while(it1 != s1.end()) { if((*it1 == *it2) && (*it2 == *it3)) { ++it1; ++it2; ++it3; } else { if(*it1 == *it2) teams = s1; else if(*it2 == *it3) teams = s2; else teams = s3; flag = false; break; } } if(flag) teams = s1; for (int i = 0; i < numlines; i++) if (s1.count(grid[2][i]) > 0 && s2.count(grid[2][i]) > 0) teams.insert(grid[2][i]); bool end = false; int y0 = -1, x1, x2; for (int y = 0; y < numlines && !end; y++) { set tmp; for (int x = 0; x < numlines && !end; x++) { if (teams.count(grid[y][x]) > 0) { // dvÄ› c if (tmp.count(grid[y][x])) { for (int i = 0; i < numlines; i++) { if (grid[y][i] == grid[y][x]) { y0 = y; x1 = i; x2 = x; end = true; break; } } } } else { for (int i = 0; i < numlines; i++) { teams.erase(grid[y][i]); } cout << y + 1 << " " << x + 1 << " " << *teams.begin() << endl; end = true; break; } tmp.insert(grid[y][x]); } } if (y0 != -1) { for (int y = 0; y < numlines; y++) { if (y0 == y) continue; if (grid[y][x1] == grid[y0][x1]) { for (int i = 0; i < numlines; i++) { teams.erase(grid[y0][i]); } cout << y0 + 1 << " " << x1 + 1 << " " << *teams.begin() << endl; break; } else if (grid[y][x2] == grid[y0][x2]) { for (int i = 0; i < numlines; i++) { teams.erase(grid[y0][i]); } cout << y0 + 1 << " " << x2 + 1 << " " << *teams.begin() << endl; break; } } } } return 0; }