Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: nate213121

Problemset: Othello

Language: cpp

Time: 0.004 second

Submitted On: 2026-09-05 18:04:52

#include <bits/stdc++.h>

using namespace std;

char otherTurn(char currTurn)
{
    if(currTurn == 'W')
    {
        return 'B';
    }
    else
    {
        return 'W';
    }
}

int main()
{
    int totalPieces = 0;
    vector<vector<char>> board(8, vector<char>(8));
    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            cin >> board[i][j];
            if(board[i][j] == 'B' || board[i][j] == 'W')
            {
                totalPieces++;
            }
        }
    }
    int r, c;
    if(totalPieces < 64)
    {
        cin >> r >> c;
    }
    else
    {
        r = -1;
        c = -1;
    }
    
    char turn = 'B';
    vector<pair<int, int>> captureOffsets = {{1, 1}, {-1, 1}, {1, -1}, {-1, -1}, {0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    while(r != -1 && c != -1 && totalPieces < 64)
    {
        board[r][c] = turn;
        totalPieces++;
        for(auto& o:captureOffsets)
        {
            int dR = o.first;
            int dC = o.second;
            int row = r + dR;
            int column = c + dC;
            vector<pair<int, int>> potentialTurnovers;
            while(row >= 0 && row < 8 && column >= 0 && column < 8 && board[row][column] == otherTurn(turn))
            {
                potentialTurnovers.push_back(make_pair(row, column));
                row += dR;
                column += dC;
            }
            if(row >= 0 && row < 8 && column >= 0 && column < 8 && board[row][column] == turn)
            {
                for(auto& c:potentialTurnovers)
                {
                    board[c.first][c.second] = turn;
                }
            }
        }
        turn = otherTurn(turn);
        if(totalPieces < 64)
        {
            cin >> r >> c;
        }
    }
    int wCount = 0;
    int bCount = 0;
    for(int i = 0; i < 8; i++)
    {
        for(int j = 0; j < 8; j++)
        {
            cout << board[i][j];
            if(board[i][j] == 'W')
            {
                wCount++;
            }
            else if(board[i][j] == 'B')
            {
                bCount++;
            }
        }
        cout << endl;
    }

    if(wCount > bCount)
    {
        cout << "white wins";
    }
    else if(bCount > wCount)
    {
        cout << "black wins";
    }
    else
    {
        cout << "draw";
    }
    return 0;
}