Hide

# Tic-Tac-Toe Solver

After years of planning, you’re finally ready to host the Tic-Tac-Toe world championships. Everything had been going great until you made a terrible discovery: the judges, who determine which player has won the game, have been taking bribes! There’s not enough time to train new ones, so you opt for a backup plan: you’ll create a piece of code that analyzes the board and tells the players if anyone has won.

A Tic-Tac-Toe board looks like the following. Every square can be empty, filled with an X, or filled with a O (capital letter ‘o’).

Player X has won if they have three X’s in a row. Player O wins if they can do the same with the O’s. A row can be horizontal, vertical, or diagonal.

Can you write the new judging code and salvage the competition?

## Input

The input consists of three lines each with $3$ characters. Each line represents a row on the board. Each character in a line represents a column. This means you have $3$ rows and $3$ columns just like a normal Tic-Tac-Toe board.

Each square in the board contains either an X, O (that’s a capital letter, not a number), or E. X and O represent markings made by the players while E represents an empty square.

## Output

If player X has won, you should print out the character X. If player O has won, you should print out the character O. If neither player has won, you should print out the character N.

Sample Input 1 Sample Output 1
XEO
EXO
EOX

X

Sample Input 2 Sample Output 2
OXO
OXX
XOX

N

Sample Input 3 Sample Output 3
XXE
EEX
OOO

O

CPU Time limit 1 second
Memory limit 1024 MB
Author
Jack Garner
Source [email protected] High School Programming Competition 2021