// 2019 IUSB Programming Competition // Round 2 Problem 2 // Find a winning move for Tic-Tac-Toe // Solution by Liguo Yu import java.util.Scanner; public class round2_p2 { public static void main(String[] main) { Scanner scan = new Scanner(System.in); int[][] board = new int[3][3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { board[i][j] = scan.nextInt(); } } int turn = scan.nextInt(); for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { if (board[i][j] == 0) { board[i][j] = turn; if (check(board, turn)) { System.out.println(i + " " + j); return; } else { board[i][j] = 0; } } } } System.out.println(-1 + " " + -1); return; } public static boolean check(int[][] a, int t) { if (a[0][0] == t && a[0][1] == t && a[0][2] == t) return true; else if (a[1][0] == t && a[1][1] == t && a[1][2] == t) return true; else if (a[2][0] == t && a[2][1] == t && a[2][2] == t) return true; else if (a[0][0] == t && a[1][0] == t && a[2][0] == t) return true; else if (a[0][1] == t && a[1][1] == t && a[2][1] == t) return true; else if (a[0][2] == t && a[1][2] == t && a[2][2] == t) return true; else if (a[0][0] == t && a[1][1] == t && a[2][2] == t) return true; else if (a[0][2] == t && a[1][1] == t && a[2][0] == t) return true; else return false; } }