Problema
A 3×3 board is given as three strings of X, O and . (empty). A player wins with three of their marks in a row, column or diagonal. Boards never have two winners.
Implement tic_tac_toe_winner(board).
Input
board: Three rows of three characters each.
Output
Return "X" or "O" for the winner, "Draw" if the board is full with no winner, or "Pending" if empty cells remain and nobody has won.
Restricciones
board has exactly 3 rows of length 3
Ejemplos
Entrada:
board = ["XOX", ".X.", "O.X"]
Salida esperada:
expected = "X"
Entrada:
std::vector<std::string> board = {"XOX", ".X.", "O.X"};
Salida esperada:
std::string expected = "X";
Entrada:
string[] board = new string[] {"XOX", ".X.", "O.X"};
Salida esperada:
string expected = "X";
Explicación
X holds the diagonal from top-left to bottom-right, so X wins.
Entrada:
board = ["XOX", "XOO", "OXX"]
Salida esperada:
expected = "Draw"
Entrada:
std::vector<std::string> board = {"XOX", "XOO", "OXX"};
Salida esperada:
std::string expected = "Draw";
Entrada:
string[] board = new string[] {"XOX", "XOO", "OXX"};
Salida esperada:
string expected = "Draw";
Explicación
The board is full and no line has three of a kind: Draw.
Referencias
Este reto está adaptado para CodeUtility. Sigue el enunciado y las restricciones indicadas arriba.