Practice

Tic-Tac-Toe Winner

HARD2D Arrays12 marks

Read a 3 by 3 board and output the winner.

Each input row contains three characters. X and O are player marks, and - is an empty square. Output X or O if that player has a complete row, column, or diagonal. Otherwise output Draw.

Input: Three strings, each with three characters. Output: X, O, or Draw.

Example:

Input:  XO-
        OX-
        --X
Output: X
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Main diagonal win
Inputs: XO-, OX-, --X
Expected: X
Test 2: Row win
Inputs: OOO, XX-, ---
Expected: O
Test 3: No winning line
Inputs: XOX, OXO, OXO
Expected: Draw