#K48832. Tic Tac Toe Outcome Checker
Tic Tac Toe Outcome Checker
Tic Tac Toe Outcome Checker
This problem requires you to determine the outcome of a classic Tic Tac Toe game. You are given a 3×3 board where each cell contains either X
, O
, or an underscore _
representing an empty cell. Your task is to decide the game result using the following rules:
- If there exists a row, column, or either of the two main diagonals that contains three identical non-empty symbols, then that symbol is the winner.
- If the board is completely filled and there is no winner, the result is
Draw
. - If the board is not completely filled and there is no winner, the result is
Pending
.
Note: When reading the board from input, empty cells are denoted with an underscore _
, which should be treated as an empty string.
For example:
Input: X O X O X O _ O X</p>Output: X
inputFormat
The input consists of 3 lines. Each line contains exactly 3 tokens separated by spaces, representing a row of the Tic Tac Toe board. Each token is either X
, O
, or _
(which represents an empty cell).
outputFormat
Output a single line containing the result of the game. The output should be one of the following strings: X
, O
, Draw
, or Pending
.
X X X
O _ O
_ O X
X