No.1016 Tic-Tac-Toe
Problem Statement
$O$ and $X$ are playing a game on a $1\times N$ grid. The game starts with $O$'s turn and proceeds as follows.
- $O$ chooses one cell in which no symbol has been written yet, and writes the symbol "o" in it.
- $X$ chooses one cell in which no symbol has been written yet, and writes the symbol "x" in it.
- Repeat 1 and 2 until symbols have been written in all cells.
This game has progressed partway, and the board in progress is given as a string $S$. It is now $O$'s turn. Determine who wins when both players play optimally.
$T$ boards are given, so make the determination for each of them.
Input
$T$ $N_1 \ S_1$ $N_2 \ S_2$ $\vdots$ $N_T \ S_T$
- $T$ is a positive integer satisfying $1\leqq T\leqq 100$.
- $N_i$ is a positive integer satisfying $1\leqq N_i\leqq 1000$.
- $S_i$ is a string of length $N_i$ consisting of the characters
o,x,-.oandxrepresent the symbols written in those cells so far, and-represents a cell in which no symbol has been written yet. - It is guaranteed that $S_i$ contains the same number of
oandx(hence it is $O$'s turn next).
Output
On the $i$-th line, output the name of the winner (O or X) for the board $S_i$.
Print a newline at the end.
Sample
Sample 1
Input
7 10 xxoo--xxoo 10 oo-ooxxxx- 10 ooxxo--oxx 10 xooo--xx-- 6 oooxxx 6 oxoxox 1 -
Output
O O X O O X X
For the $1$st board xxoo--xxoo, if $O$ writes o in the left empty cell,
the grid at the end of the game becomes xxoooxxxoo, which satisfies $O$'s winning condition.
For the $2$nd board, if $O$ writes o in the left empty cell,
the grid at the end of the game becomes oooooxxxxx. Here o appears in $5$ consecutive cells, and $O$'s winning condition is satisfied in this case as well.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
maspy
beet