#K46497. Tic Tac Toe Winner Checker
Tic Tac Toe Winner Checker
Tic Tac Toe Winner Checker
You are given a 3x3 Tic Tac Toe board. Each cell is represented by an integer: 0 for an empty cell, 1 for a move made by player 1, and 2 for a move made by player 2.
Your task is to determine if any player has won the game. A player wins if they have filled any row, column, or diagonal with their marker. In mathematical terms, for any row i (with 0 \leq i \leq 2), if board[i][0] = board[i][1] = board[i][2] \neq 0, then the corresponding player wins. The same applies to any column and the two diagonals:
- Main diagonal: board[0][0] = board[1][1] = board[2][2] \neq 0
- Anti-diagonal: board[0][2] = board[1][1] = board[2][0] \neq 0
If no such condition holds, then the game has no winner.
inputFormat
The input consists of exactly 3 lines. Each line contains 3 integers separated by spaces, representing a row of the Tic Tac Toe board.
For example:
1 2 0 2 1 0 2 1 2
outputFormat
Output a single integer to stdout: 1 if player 1 wins, 2 if player 2 wins, and 0 if there is no winner.
## sample1 2 0
2 1 0
2 1 2
0