Submission
Status:
PPPPPPPPPPPPPPPPPPPP
Subtask/Task Score:
100/100
Score: 100
User: loop
Problemset: Othello
Language: cpp
Time: 0.002 second
Submitted On: 2026-10-10 18:42:12
#include <iostream>
#include <string>
using namespace std;
char b[8][9];
bool full() {
for (int r = 0; r < 8; r++)
for (int c = 0; c < 8; c++)
if (b[r][c] == '_') return false;
return true;
}
int main() {
for (int r = 0; r < 8; r++) {
string line;
cin >> line;
for (int c = 0; c < 8; c++) b[r][c] = line[c];
}
char me = 'B';
int R, C;
while (!full() && cin >> R >> C) {
if (R == -1 && C == -1) break;
if (b[R][C] != '_') continue; // occupied: ignored, same player again
char other = me == 'B' ? 'W' : 'B';
b[R][C] = me;
for (int dr = -1; dr <= 1; dr++)
for (int dc = -1; dc <= 1; dc++) {
if (dr == 0 && dc == 0) continue;
int r = R + dr, c = C + dc, run = 0;
while (r >= 0 && r < 8 && c >= 0 && c < 8 && b[r][c] == other) { r += dr; c += dc; run++; }
if (run > 0 && r >= 0 && r < 8 && c >= 0 && c < 8 && b[r][c] == me)
for (int k = 1; k <= run; k++) b[R + dr * k][C + dc * k] = me;
}
me = other;
}
int black = 0, white = 0;
for (int r = 0; r < 8; r++) {
for (int c = 0; c < 8; c++) {
cout << b[r][c];
if (b[r][c] == 'B') black++;
if (b[r][c] == 'W') white++;
}
cout << '\n';
}
if (black > white) cout << "black wins" << '\n';
else if (white > black) cout << "white wins" << '\n';
else cout << "draw" << '\n';
return 0;
}