#C10136. Tic Tac Toe Outcome
Tic Tac Toe Outcome
Tic Tac Toe Outcome
In this problem, you are given the final states of one or more Tic Tac Toe games. Each game is played on a 3 (3\times3) grid. The board is represented by three lines of three characters, where each character is either X
, O
, or .
(a dot). The dot indicates an empty cell. A player wins if they have three of their marks in a row, column, or one of the two main diagonals. Formally, for a row (i) (with (1 \leq i \leq 3)), if (a_{i,1} = a_{i,2} = a_{i,3}) and the mark is not .
, then that player wins. Similarly, for a column (j) (with (1 \leq j \leq 3)) if (a_{1,j} = a_{2,j} = a_{3,j}) and the mark is not .
, then that player wins. The diagonal conditions are: if (a_{1,1} = a_{2,2} = a_{3,3}) or (a_{1,3} = a_{2,2} = a_{3,1}) and they are not .
, the corresponding player wins. If neither player has met these conditions and there is still at least one empty cell, the game is considered Ongoing. Otherwise, if the board is full without any player winning, the result is Draw.
You are required to determine and print the outcome for each board.
inputFormat
The input is read from standard input (stdin). The first line contains an integer (T) ((1 \leq T \leq 1000)) representing the number of game boards. For each board, there are exactly 3 subsequent lines, each containing 3 characters (X
, O
, or .
) without spaces.
outputFormat
For each game board, print the outcome on a separate line. The outcome should be one of: X wins
, O wins
, Draw
, or Ongoing
.## sample
3
XOX
OXO
X..
OOX
XX.
OX.
OXO
XOX
OX.
X wins
O wins
Draw
</p>