Submission
Status:
P----P-P--PP-P----PP
Subtask/Task Score:
40/100
Score: 40
User: ChanakanStudy
Problemset: Othello
Language: cpp
Time: 0.004 second
Submitted On: 2026-10-16 00:58:34
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <numeric>
#include <iomanip>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
char table[8][8];
for(int i = 0;i<8;i++) {
for(int j = 0;j<8;j++) {
cin >> table[i][j];
}
}
int turn = 0;
char setal[2] = {'B' , 'W'};
while(true) {
int x,y;
cin >> x >> y;
if(x == -1 && y == -1) {
break;
}
else {
table[x][y] = setal[turn%2];
}
// check up
int nowcheck = x , bestx = x , startx = x;
while(nowcheck != 0) {
nowcheck--;
if(table[nowcheck][y] == '_') {
// cout << nowcheck << " " << y << " ";
// cout << "pass";
break;
}
else if(table[nowcheck][y] == setal[turn%2]) {
bestx = nowcheck;
break;
}
}
while(startx != bestx) {
table[startx][y] = setal[turn%2];
startx--;
}
//check down
nowcheck = x;
bestx = x;
startx = x;
while(nowcheck != 7) {
nowcheck++;
if(table[nowcheck][y] == '_') {
// cout << nowcheck << " " << y << " ";
// cout << "pass";
break;
}
else if(table[nowcheck][y] == setal[turn%2]) {
bestx = nowcheck;
break;
}
}
while(startx != bestx) {
table[startx][y] = setal[turn%2];
startx++;
}
//check left
nowcheck = y;
int besty = y;
int starty = y;
while(nowcheck != 0) {
nowcheck--;
if(table[x][nowcheck] == '_') {
// cout << nowcheck << " " << y << " ";
// cout << "pass";
break;
}
else if(table[x][nowcheck] == setal[turn%2]) {
besty = nowcheck;
break;
}
}
while(starty != besty) {
table[x][starty] = setal[turn%2];
starty--;
}
// check right
nowcheck = y;
besty = y;
starty = y;
while(nowcheck != 7) {
nowcheck++;
if(table[x][nowcheck] == '_') {
// cout << nowcheck << " " << y << " ";
// cout << "pass";
break;
}
else if(table[x][nowcheck] == setal[turn%2]) {
besty = nowcheck;
break;
}
}
while(starty != besty) {
table[x][starty] = setal[turn%2];
starty++;
}
turn++;
}
int countB = 0 , countW = 0;
for(int i = 0;i<8;i++) {
for(int j = 0;j<8;j++) {
if(table[i][j] == 'B') {
countB++;
}
else if (table[i][j] == 'W') {
countW++;
}
}
}
for(int i = 0;i<8;i++) {
for(int j = 0;j<8;j++) {
cout << table[i][j];
}
cout << '\n';
}
if(countB > countW) {
cout << "black wins";
}
else if(countW > countB) {
cout << "white wins";
}
else {
cout << "draw";
}
return 0;
}