// 2019 IUSB Programming Competition // Round 2 Problem 2 // Find a winning move for Tic-Tac-Toe // Solution by Liguo Yu #include using namespace std; bool check(int ** b, int p); int main() { int ** game = new int *[3]; for (int i = 0; i < 3; i++) { game[i] = new int[3]; } for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { cin >> game[i][j]; } } int turn; cin >> turn; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (game[i][j] == 0) { game[i][j] = turn; if (check(game, turn)) { cout << i << " " << j; return 0; } else game[i][j] = 0; } } } cout << -1 << " " << -1; return 0; } bool check(int ** b, int t) { if (b[0][0] == t && b[0][1] == t && b[0][2] == t) return true; else if (b[1][0] == t && b[1][1] == t && b[1][2] == t) return true; else if (b[2][0] == t && b[2][1] == t && b[2][2] == t) return true; else if (b[0][0] == t && b[1][0] == t && b[2][0] == t) return true; else if (b[0][1] == t && b[1][1] == t && b[2][1] == t) return true; else if (b[0][2] == t && b[1][2] == t && b[2][2] == t) return true; else if (b[0][0] == t && b[1][1] == t && b[2][2] == t) return true; else if (b[0][2] == t && b[1][1] == t && b[2][0] == t) return true; else return false; }