CF3C 暴力

http://codeforces.com/problemset/problem/3/C

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 a3 × 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: firstsecondillegalthe first player wonthe second player won or draw.

Sample test(s)
input
X0X
.0.
.X.
output
second

/**
CF3C 暴力
题目大意:给定一个3*3的棋盘,判断现在的情况下是属于什么状态(状态有6种)
解题思路:判断非法的时候要注意如果已经出现赢的情况了,棋盘就必须结束。其余就是简单暴力
*/
#include <string.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std;
char a[5][5];
int cnt0,cntx;
bool win(char x)
{
    if(a[0][0]==x&&a[0][1]==x&&a[0][2]==x)return true;
    if(a[1][0]==x&&a[1][1]==x&&a[1][2]==x)return true;
    if(a[2][0]==x&&a[2][1]==x&&a[2][2]==x)return true;
    if(a[0][0]==x&&a[1][0]==x&&a[2][0]==x)return true;
    if(a[0][1]==x&&a[1][1]==x&&a[2][1]==x)return true;
    if(a[0][2]==x&&a[1][2]==x&&a[2][2]==x)return true;
    if(a[2][0]==x&&a[1][1]==x&&a[0][2]==x)return true;
    if(a[0][0]==x&&a[1][1]==x&&a[2][2]==x)return true;
    return false;
}
bool judge()
{
    if(win('X')&&cntx==cnt0)return true;
    if(win('0')&&cntx==cnt0+1)return true;
    if(cntx>cnt0+1||cntx<cnt0)return true;
    return false;
}
int main()
{
    for(int i=0;i<3;i++)
    {
        scanf("%s",a[i]);
    }
    cnt0=0,cntx=0;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(a[i][j]=='0')
            {
                cnt0++;
            }
            if(a[i][j]=='X')
            {
                cntx++;
            }
        }
    }
    if(judge())
    {
        printf("illegal\n");
    }
    else if(win('0'))
    {
        printf("the second player won\n");
    }
    else if(win('X'))
    {
        printf("the first player won\n");
    }
    else if(cnt0+cntx==9)
    {
        printf("draw\n");
    }
    else if(cnt0==cntx)
    {
       printf("first\n");
    }
    else
    {
       printf("second\n");
    }
    return 0;
}
/**
X0.
...
...

X0X
0X0
0X0

XXX
XXX
XXX

000
X..
...

0X.
X0.
...

X0X
0X0
X0X
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
H3C CF8800是一款高性能的企业级交换机设备,用户手册是为了帮助用户正确配置和使用这款设备而编写的详细指南。 H3C CF8800用户手册主要包括以下内容: 1. 产品介绍:介绍了CF8800交换机的主要特点和硬件结构,包括端口配置、指示灯功能等。用户可以通过阅读这部分内容了解设备的基本情况。 2. 硬件安装:详细介绍了CF8800的安装步骤,包括机柜安装、电源连接、网线连接、风扇插入等。用户可以按照手册中给出的指引一步步完成设备的安装。 3. 系统配置:介绍了CF8800的系统配置方法,包括设备开机、登录认证、管理口配置等。用户可以根据手册中的说明设置设备的基本参数。 4. VLAN配置:详细介绍了CF8800的VLAN配置方法,包括新建VLAN、端口划分、端口模式设置等。用户可以根据手册中的指引配置设备的VLAN。 5. 路由配置:介绍了CF8800的路由配置方法,包括静态路由、动态路由、路由汇总等。用户可以按照手册中给出的步骤配置设备的路由。 6. 安全配置:详细介绍了CF8800的安全配置方法,包括访问控制列表(ACL)、端口安全、防护组等。用户可以根据手册中的说明加强设备的安全性。 总之,H3C CF8800用户手册是一本重要的工具,可以帮助用户快速熟悉设备的各项功能和配置方法。用户在使用CF8800交换机时,可以随时参考手册来解决设备配置和使用过程中的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值