Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: wleo.lwo

Problemset: Othello

Language: cpp

Time: 0.004 second

Submitted On: 2026-10-09 10:35:57

#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {

    vector<string> mp(8);

    
    for (int i = 0; i < 8; i++) {
        cin >> mp[i];
    }

    
    int dx[8] = {0, -1, -1, -1, 0, 1, 1, 1};
    int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

    char color = 'B'; 


    while (true) {

        bool full = true;

        for (int i = 0; i < 8; i++) {
            for (int j = 0; j < 8; j++) {
                if (mp[i][j] == '_') {
                    full = false;
                }
            }
        }

        
        if (full == true) {
            break;
        }


        int x, y;

        
        if (!(cin >> x >> y)) {
            break;
        }

        
        if (x == -1 && y == -1) {
            break;
        }


        
        mp[x][y] = color;


        
        char other;

        if (color == 'B') {
            other = 'W';
        }
        else {
            other = 'B';
        }


        for (int d = 0; d < 8; d++) {

            int nx = x + dx[d];
            int ny = y + dy[d];


            if (nx < 0 || nx >= 8 ||
                ny < 0 || ny >= 8) {

                continue;
            }


            if (mp[nx][ny] != other) {
                continue;
            }


            while (nx >= 0 && nx < 8 &&
                   ny >= 0 && ny < 8 &&
                   mp[nx][ny] == other) {

                nx += dx[d];
                ny += dy[d];
            }


            if (nx < 0 || nx >= 8 ||
                ny < 0 || ny >= 8) {

                continue;
            }


            if (mp[nx][ny] != color) {
                continue;
            }


            int fx = x + dx[d];
            int fy = y + dy[d];

            while (fx != nx || fy != ny) {

                mp[fx][fy] = color;

                fx += dx[d];
                fy += dy[d];
            }
        }


        
        if (color == 'B') {
            color = 'W';
        }
        else {
            color = 'B';
        }
    }



    int black = 0;
    int white = 0;

    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {

            if (mp[i][j] == 'B') {
                black++;
            }
            else if (mp[i][j] == 'W') {
                white++;
            }
        }
    }
    for (int i = 0; i < 8; i++) {
        cout << mp[i] << '\n';
    }

    if (black > white) {
        cout << "black wins\n";
    }
    else if (white > black) {
        cout << "white wins\n";
    }
    else {
        cout << "draw\n";
    }

    return 0;
}