Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
734 B
21
Indexable
Never
#include <cstring>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define result num_of_X - num_of_O
int getWinner (char * path){
    ifstream file(path);
    int n; file >>n;
    int a[n][n];
    int num_of_X = 0;
    int num_of_O = 0;
    rep (i,0,n-1){
        rep(j,0,n-1){
            char x; file>>x;
            if (x=='X') {a[i][j]=-1; num_of_X++;};
            if (x=='O') {a[i][j]=1; num_of_O++;};
        }
    }
    
    rep (i,1,n-2){
        rep(j,1,n-2){
            if (a[i][j]>0&&a[i-1][j]==-1&&a[i+1][j]==-1&&a[i][j-1] ==-1&&a[i][j+1]==-1){
                num_of_X++;
                num_of_O--;
            }    
        }
    }
    if (result>0) return -1;
    if (result ==0) return 0;
    if (result <0) return 1;
}