Trung bình 0 đã giải Tỷ lệ chấp nhận 0%

Tic-Tac-Toe Winner

Decide the result of a tic-tac-toe board.

Đề bài

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.

Ràng buộc

board has exactly 3 rows of length 3

Ví dụ

Ví dụ 1
Đầu vào:
board = ["XOX", ".X.", "O.X"]

Kết quả mong đợi:
expected = "X"
Đầu vào:
std::vector<std::string> board = {"XOX", ".X.", "O.X"};

Kết quả mong đợi:
std::string expected = "X";
Đầu vào:
string[] board = new string[] {"XOX", ".X.", "O.X"};

Kết quả mong đợi:
string expected = "X";

Giải thích

X holds the diagonal from top-left to bottom-right, so X wins.

Ví dụ 2
Đầu vào:
board = ["XOX", "XOO", "OXX"]

Kết quả mong đợi:
expected = "Draw"
Đầu vào:
std::vector<std::string> board = {"XOX", "XOO", "OXX"};

Kết quả mong đợi:
std::string expected = "Draw";
Đầu vào:
string[] board = new string[] {"XOX", "XOO", "OXX"};

Kết quả mong đợi:
string expected = "Draw";

Giải thích

The board is full and no line has three of a kind: Draw.

Tham khảo

Thử thách này đã được điều chỉnh cho CodeUtility. Hãy làm theo đề bài và các ràng buộc ở trên.

Học hỏi từ người khác

Giải pháp cộng đồng

Chưa có giải pháp nào được chia sẻ. Hãy giải thử thách này để đăng giải pháp đầu tiên.