Submission

Status:
PPPPPPPPPPPPPPP-P-PP

Score: 90

User: Namkhing

Problemset: Othello

Language: cpp

Time: 0.002 second

Submitted On: 2025-04-11 17:27:58

#include <bits/stdc++.h>
using namespace std;

const int dirX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dirY[] = {-1, 0, 1, -1, 1, -1, 0, 1};

string a[8];

int main() {
    cin.tie(nullptr)->ios_base::sync_with_stdio(false);
    for (int i = 0; i < 8; i++) cin >> a[i];
    int cnt = 0;
    for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) if (a[i][j] != '_') cnt++;
    int now = 0; // black
    while (true) {
        int x, y;
        cin >> x >> y;
        if (x == -1 && y == -1) break;
        char c;
        if (now == 0) c = 'B';
        else c = 'W';
        if (a[x][y] != '_') break;
        a[x][y] = c;
        for (int k = 0; k < 8; k++) {
            int i = x, j = y;
            while (true) {
                int di = i + dirX[k];
                int dj = j + dirY[k];
                if (di < 0 || di >= 8 || dj < 0 || dj >= 8 || a[di][dj] == '_') break;
                if (a[di][dj] == c) {
                    for (int u = x, v = y; u != di || v != dj; u += dirX[k], v += dirY[k]) a[u][v] = c;
                    break;
                }
                i = di, j = dj;
            }
        }
        now = 1 - now;
        cnt++;
        if (cnt == 64) break;
    }
    for (int i = 0; i < 8; i++) cout << a[i] << "\n";
    int b = 0, w = 0;
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            if (a[i][j] == 'B') b++;
            else if (a[i][j] == 'W') w++;
        }
    }
    if (b > w) cout << "black wins";
    else if (b < w) cout << "white wins";
    else cout << "draw";
}