Johnbug

It's too late to apologize, it's too late~

CF 3C Tic-tac-toe

考虑全面!!

#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;

}


阅读更多
文章标签: c
个人分类: CF
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

CF 3C Tic-tac-toe

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭