5744: 井字游戏

内存限制:256 MB 时间限制:2 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:3 通过:1

题目描述

C. 井字游戏
每次测试的时间限制
1 秒
每个测试的内存限制
64 兆字节
输入
标准输入
输出
标准输出
当然,每个人都熟悉井字游戏。规则确实很简单。两名玩家轮流在 3×3 网格中标记单元格(一名玩家总是画十字架,另一名玩家 - noughts)。首先成功将三个标记放在水平、垂直或对角线上的玩家获胜,游戏结束。抽到十字架的球员先走。如果网格已填充,但 X 和 0 均未构成所需的行,则宣布平局。
你得到一个 3×3 的网格,每个网格单元格都是空的,或者被一个十字或一个零占据。您必须找到下一个轮到谁的玩家(第一个或第二个),或者打印以下判决之一:

  • 非法 − 如果给定的棋盘布局在有效游戏中无法出现;
  • 第一个玩家赢了 - 如果在给定的棋盘布局中第一个玩家刚刚获胜;
  • 第二个玩家赢了 - 如果在给定的棋盘布局中,第二个玩家刚刚获胜;
  • 绘制 − 如果给定的板布局刚刚允许绘制
输入
输入由三行组成,每行包含字符“.”、“X”或“0”(句点、大写字母 X 或数字零)。
输出
打印六个判决之一:第一个,第二个,非法第一个玩家赢了,第二个玩家赢平局
例子
输入
X0X
.0.
.X.
输出
second
C. Tic-tac-toe
time limit per test
1 second
memory limit per test
64 megabytes
input
standard input
output
standard output
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

输入样例 复制


输出样例 复制


分类标签