Previous
0 / 21
Module DEMO-32-109DEMO-C-32

Tic-Tac-Toe

DEMO-C-32 โ€ข Programming in C

Browser-only practice

Problem Statement

Write a program to check the winner of a 3x3 Tic-Tac-Toe board (0=Empty, 1=X, 2=O). Print 1 if X wins, 2 if O wins, or 0 otherwise.

Constraints

1 <= N, M <= 10. Integers within standard range.

Input Format

Input: Dimensions N M followed by the matrix elements.

Output Format

Output: The formatted result as specified.

Sample Testcases

Submit runs every public testcase in this browser. Results and code never leave this device.

Sample #1
Public sample
3 3
2 2 2
1 2 1
2 1 2
2
Player 2 (O) Wins.
Sample #2
Public sample
3 3
2 2 0
2 1 1
2 1 0
2
Player 2 (O) Wins.
Sample #3
Public sample
3 3
1 1 0
2 0 0
0 1 1
0
Draw or ongoing.
Sample #4
Public sample
3 3
0 2 0
1 1 0
1 1 1
1
Player 1 (X) Wins.

Web terminal

C, C++, Java, and Python run locally in a browser VM. No worker or visualizer is used.

Saved in this browser
Editor settings