Codeforces 3C Tic-tac-toe

来源:互联网 发布:sql identity 编辑:程序博客网 时间:2024/05/19 16:47

English

Desc

Certainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. Two players take turns marking the cells in a 3 × 3 grid (one player always draws crosses, the other — noughts). The player who succeeds first in placing three of his marks in a horizontal, vertical or diagonal line wins, and the game is finished. The player who draws crosses goes first. If the grid is filled, but neither Xs, nor 0s form the required line, a draw is announced.

You are given a 3 × 3 grid, each grid cell is empty, or occupied by a cross or a nought. You have to find the player (first or second), whose turn is next, or print one of the verdicts below:

  • illegal — if the given board layout can’t appear during a valid game;
  • the first player won — if in the given board layout the first player has just won;
  • the second player won — if in the given board layout the second player has just won;
  • draw — if the given board layout has just let to a draw.

Input

The input consists of three lines, each of the lines contains characters “.”, “X” or “0” (a period, a capital letter X, or a digit zero).

Output

Print one of the six verdicts: first, second, illegal, the first player won, the second player won or draw.

Examples

input

X0X.0..X.

output

second

中文

简介

当然,每个人都熟悉tic-tac-toe游戏。规则很简单。两名球员轮流在3×3格网格中标注图案(first总是画X,second球员则是O)。第一次在水平,垂直或对角线上放置三个标记的人就赢了,游戏结束。画X的玩家先行。如果网格已经填充,但是X和0都不会形成所需的行,则会输出一个图。

给你一个3×3的网格,每个网格单元都是空的,或被十字架还是一个空的。你必须找到玩家(第一个或第二个),其次是下一个,或打印下面的一个裁决:

  • illegal–如果给定的棋盘布局在有效的游戏中不能出现
  • the first player won —如果在给定的棋盘布局中,第一名玩家刚刚赢了;
  • the second player won — 如果在给定的棋盘布局中,第二名玩家刚刚赢了;
  • draw — 绘制 - 如果给定的板布局刚刚让一幅画。

输入格式

输入由三行组成,每行包含字符“ . ”,“ X ”或“ 0 ”(一个句点,大写字母X或数字零)。

输出格式

打印六个输出之一:first,second,illegal, the first player won ,the second player won ,draw

测试用例

测试输入

X0X.0..X.

测试输出

second
0 0
原创粉丝点击