Hide

Problem F
Who can win?

Languages en sv

Johan and Abdullah are still playing tic-tac-toe, so now they want help figuring out who can still win in their game. To win in tic-tac-toe you need to have three of your letter in a row, either vertically, horizontally, or diagonally. Johan uses the letter X and makes the first move, and Abdullah uses the letter O. This implies that Johan could at most have $5$ X-pieces on the board, while Abdullah could at most have $4$ O-pieces. It is guaranteed that no one has won.

Input

Input consists of a valid tic-tac-toe position, where an underscore _ represents an empty square, and the letters X and O represent Johan’s and Abdullah’s moves. The position is described by three rows, each containing three space-separated characters each. It is guaranteed that no player has already won.

Output

Print who can still win, if anyone. If both Johan and Abdullah can still win, then print “Abdullah och Johan kan vinna”. If only one person can win, print their name, then “kan vinna”. If no player can win, then print “ingen kan vinna”.

Grading

Your solution will be tested on a number of test-case groups. To receive points for a group, your solution must handle every test-case in the group.

Group

Point value

Restrictions

$1$

$5$

All squares are filled

$2$

$65$

Either Abdullah or Johan can win, not both

$3$

$30$

No further restrictions

Sample Input 1 Sample Output 1
_ _ _
_ _ _
_ _ _
Abdullah och Johan kan vinna
Sample Input 2 Sample Output 2
X O X
X O X
O X O
ingen kan vinna
Sample Input 3 Sample Output 3
X O X
X O O
_ X O
Johan kan vinna

Please log in to submit a solution to this problem

Log in