CF 3C Tic-tac-toe

原创 2012年03月29日 19:41:45

考虑全面!!

#include <iostream>
using namespace std;
char m[3][3];
bool fwin()
{
    if((m[0][0] == m[0][1]&&m[0][1]==m[0][2]&&m[0][0] == 'X')||
       (m[1][0] == m[1][1]&&m[1][1]==m[1][2]&&m[1][0] == 'X')||
       (m[2][0] == m[2][1]&&m[2][1]==m[2][2]&&m[2][0] == 'X')||
       (m[0][0] == m[1][0]&&m[1][0]==m[2][0]&&m[0][0] == 'X')||
       (m[0][1] == m[1][1]&&m[1][1]==m[2][1]&&m[0][1] == 'X')||
       (m[0][2] == m[1][2]&&m[1][2]==m[2][2]&&m[0][2] == 'X')||
       (m[0][0] == m[1][1]&&m[1][1]==m[2][2]&&m[0][0] == 'X')||
       (m[0][2] == m[1][1]&&m[1][1]==m[2][0]&&m[0][2] == 'X'))
       return 1;
    else return 0;
}
bool swin()
{
    if((m[0][0] == m[0][1]&&m[0][1]==m[0][2]&&m[0][0] == '0')||
       (m[1][0] == m[1][1]&&m[1][1]==m[1][2]&&m[1][0] == '0')||
       (m[2][0] == m[2][1]&&m[2][1]==m[2][2]&&m[2][0] == '0')||
       (m[0][0] == m[1][0]&&m[1][0]==m[2][0]&&m[0][0] == '0')||
       (m[0][1] == m[1][1]&&m[1][1]==m[2][1]&&m[0][1] == '0')||
       (m[0][2] == m[1][2]&&m[1][2]==m[2][2]&&m[0][2] == '0')||
       (m[0][0] == m[1][1]&&m[1][1]==m[2][2]&&m[0][0] == '0')||
       (m[0][2] == m[1][1]&&m[1][1]==m[2][0]&&m[0][2] == '0'))
       return 1;
    else return 0;
}
int main()
{
    int i,j,f = 0,s = 0;
    bool full = 1;
    for(i = 0;i < 3;i ++)
    {
        for(j = 0;j < 3;j ++)
        {
            cin>>m[i][j];
            if(m[i][j] =='.') full = 0;
            else if(m[i][j] == 'X') f ++;
            else s ++;
        }
    }
    if(f == s||f == s + 1)
    {
        if(full)
        {
            if(fwin()) {if(f == s+1){if(swin())cout<<"illegal"<<endl;else  cout<<"the first player won"<<endl;}else cout<<"illegal"<<endl;}
            else if(swin()) {if(f==s+1)cout<<"illegal"<<endl;else cout<<"the second player won"<<endl;}
            else cout<<"draw"<<endl;
        }
        else
        {
            if(fwin())  {if(f == s+1){if(swin())cout<<"illegal"<<endl;else  cout<<"the first player won"<<endl;}else cout<<"illegal"<<endl;}
            else if(swin()) {if(f==s+1)cout<<"illegal"<<endl;else cout<<"the second player won"<<endl;}
            else if(f == s) cout<<"first"<<endl;
            else cout<<"second"<<endl;
        }
    }
    else cout<<"illegal" <<endl;

}


相关文章推荐

Codeforces Beta Round #3-C. Tic-tac-toe

题意: 就是给你一个井字棋的棋面,然后让你判断当前属于哪种情况。 思路: 首先就是判断不合法的情况没有考虑清楚。 最重要的一点是我们应该先判断X是否赢,因为它是先手,然后再判断0是否赢。 其...

CodeForces 3C Tic-tac-toe 井字棋盘游戏

CodeForces 3C Tic-tac-toe 井字棋盘游戏
  • wilver
  • wilver
  • 2015年07月09日 10:14
  • 458

codeforces 3C Tic-tac-toe

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes inpu...
  • ahoLic
  • ahoLic
  • 2014年04月03日 13:00
  • 2309

Codeforces 3C Tic-tac-toe

EnglishDescCertainly, everyone is familiar with tic-tac-toe game. The rules are very simple indeed. ...

Codeforces Beta Round #3 C. Tic-tac-toe

井字棋 ,这个模拟也是醉了 题目大意: 给出一个井字棋棋局,判断他是不是合法的。若合法且出现某人赢是谁赢了,没出现某人赢是下一步该谁下,还是平局。 解题思路: 分类讨论...

Codeforces 3C. Tic-tac-toe

C. Tic-tac-toe time limit per test 1 second memory limit per test 64 megabytes inpu...

CF - 754B. Ilya and tic-tac-toe game 模拟+暴力

1.题目描述: B. Ilya and tic-tac-toe game time limit per test 2 seconds memory ...

Principle of Computing (Python)学习笔记(3) probability +Objects and reference + tic_tac_toe

1 Basic Probability    https://class.coursera.org/principlescomputing-001/wiki/view?page=probabilit...

C - Tic-tac-toe

C - Tic-tac-toe Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u...

Tic-tac-toe mathematica 制作模拟

  • 2015年08月26日 09:49
  • 38KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:CF 3C Tic-tac-toe
举报原因:
原因补充:

(最多只允许输入30个字)