ปานกลาง 0 ข้อที่แก้แล้ว อัตราผ่าน 0%

Tic-Tac-Toe Winner

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

โจทย์

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.

เงื่อนไข

board has exactly 3 rows of length 3

ตัวอย่าง

ตัวอย่างที่ 1
อินพุต:
board = ["XOX", ".X.", "O.X"]

ผลลัพธ์ที่คาดหวัง:
expected = "X"
อินพุต:
std::vector<std::string> board = {"XOX", ".X.", "O.X"};

ผลลัพธ์ที่คาดหวัง:
std::string expected = "X";
อินพุต:
string[] board = new string[] {"XOX", ".X.", "O.X"};

ผลลัพธ์ที่คาดหวัง:
string expected = "X";

คำอธิบาย

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

ตัวอย่างที่ 2
อินพุต:
board = ["XOX", "XOO", "OXX"]

ผลลัพธ์ที่คาดหวัง:
expected = "Draw"
อินพุต:
std::vector<std::string> board = {"XOX", "XOO", "OXX"};

ผลลัพธ์ที่คาดหวัง:
std::string expected = "Draw";
อินพุต:
string[] board = new string[] {"XOX", "XOO", "OXX"};

ผลลัพธ์ที่คาดหวัง:
string expected = "Draw";

คำอธิบาย

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

แหล่งอ้างอิง

โจทย์นี้ปรับให้เหมาะกับ CodeUtility กรุณาทำตามคำชี้แจงและข้อจำกัดด้านบน

เรียนรู้จากคนอื่น

แนวทางจากชุมชน

ยังไม่มีวิธีทำที่เผยแพร่ ลองแก้โจทย์นี้เพื่อแชร์วิธีแรก