求助,wa on #4
查看原帖
求助,wa on #4
523541
Onana_in_XMFLS楼主2022/6/22 23:07
#include <bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define mem(arr,val) memset((arr),(val),(sizeof(arr)))
#define V(x) vector <x>
using namespace std;
char c[5][5];
int A,B;
inline bool success(char ch)
{
    for(int i = 1;i <= 3;++i)
    {
        if(c[i][1] == c[i][2] == c[i][3] == ch) return true;
        if(c[1][i] == c[2][i] == c[3][i] == ch) return true;
    }
    if(c[1][1] == c[2][2] == c[3][3] == ch) return true;
    if(c[3][1] == c[2][2] == c[1][3] == ch) return true;
    return false;
        
}
int main(int argc,char *argv[])
{
    for(int i = 1;i <= 3;++i)
        for(int j = 1;j <= 3;++j) 
        {
            cin>>c[i][j];
            if(c[i][j] == 'X') ++A;
            else if(c[i][j] == '0') ++B;
        }
    if(A != B && A != B+1) puts("illegal");
    else if(success('X')) puts("the first player won");
    else if(success('0')) puts("the second player won");
    else if(A == B) puts("first");
    else if(A == B+1) puts("second");
    else if(A+B == 9 && (!success('X') && !success('0'))) puts("draw");
    return 0;
}

2022/6/22 23:07
加载中...