TSS Contest P6 - Tic Tac Toe

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem type

Tic Tac Toe is a game played on a 3x3 grid. The two players take turns placing an x or an o on an unoccupied cell. A player wins when they have three matching symbols in a vertical, horizontal or diagonal line. If no one wins after all 9 cells have been taken the game results in a draw. If a player can create a situation where there are two possible moves to win the game, they are guaranteed an opportunity to win if the game does not end before their next turn. This is because the opposing player can block one of the win conditions but must leave at least one of them open. Given the state of a Tic Tac Toe board and assuming both players play optimally, determine if the player playing x is guaranteed to win the game if it is the other player's turn to move as o.

Input Specification

The input is 3 lines each containing 3 characters, either an x, o or - representing an x, o or blank space in that cell of the board. This board state is guaranteed to not already be over, meaning no player already has 3 in a row and there is still at least 1 empty cell.

Output Specification

If x is guaranteed a winning move on their next turn, print yes. Otherwise, print no.

Sample Input

o--
-xo
x-x

Sample Output

yes

Comments

There are no comments at the moment.