Submission

Status:

PPPPPP-PPPPP-P----PP

Subtask/Task Score:

70/100

Score: 70

User: wleo.lwo

Problemset: Othello

Language: cpp

Time: 0.002 second

Submitted On: 2026-10-07 14:34:04

#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];
}

// 8 ทิศ
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) {
int x, y;
cin >> x >> y;

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

mp[x][y] = color;

// ลองทั้ง 8 ทิศ
for (int d = 0; d < 8; d++) {

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

// เดินไปเรื่อย ๆ จนกว่าจะหลุดกระดาน
while (nx >= 0 && nx < 8 &&
ny >= 0 && ny < 8) {

// เจอช่องว่าง แปลว่าทิศนี้พลิกไม่ได้
if (mp[nx][ny] == '_') {
break;
}

// เจอสีของตัวเอง
if (mp[nx][ny] == color) {

// เดินย้อนจากตัวที่วาง
// แล้วพลิกตัวที่อยู่ตรงกลาง
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];
}

break;
}

// ยังเป็นสีตรงข้าม เดินต่อ
nx += dx[d];
ny += dy[d];
}
}

// สลับสี
if (color == 'B') {
color = 'W';
}
else {
color = 'B';
}
}


// นับจำนวน B และ W
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++;
}

if (mp[i][j] == 'W') {
white++;
}
}
}


// แสดงกระดาน
for (int i = 0; i < 8; i++) {
cout << mp[i] << '\n';
}


// หาผู้ชนะ
if (black > white) {
cout << "black wins";
}
else if (white > black) {
cout << "white wins";
}
else {
cout << "draw";
}

return 0;
}