Submission
Status:
PPPPPP-PPPPP-P----PP
Subtask/Task Score:
70/100
Score: 70
User: PROb221
Problemset: Othello
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-14 06:58:02
#include <iostream>
#include <string>
#define n 8
using namespace std;
string arr[n];
int i,j,x,y,b_score=0,w_score=0;
char turn;
void show() {
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
cout << arr[i][j];
}
cout << "\n";
}
}
void result() {
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
if(arr[i][j]=='B'){b_score++;}
if(arr[i][j]=='W'){w_score++;}
}
}
if(b_score==w_score){cout<<"draw";}
if(b_score>w_score){cout<<"black wins";}
if(b_score<w_score){cout<<"white wins";}
}
bool isfull() {
bool full=true;
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
if(arr[i][j]=='W'||arr[i][j]=='B') {continue;}
full=false;
}
}
return full;
}
void right(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x,j=y+1;j<8;j++) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x,j=y+1;j<8;j++) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void left(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x,j=y-1;j>=0;j--) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x,j=y-1;j>=0;j--) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void down(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x+1,j=y;i<8;i++) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x+1,j=y;i<8;i++) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void up(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x-1,j=y;i>=0;i--) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x-1,j=y;i>=0;i--) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void downright(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x+1,j=y+1;i<8&&j<8;i++,j++) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x+1,j=y+1;i<8&&j<8;i++,j++) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void downleft(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x+1,j=y-1;i<8&&j>=0;i++,j--) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x+1,j=y-1;i<8&&j>=0;i++,j--) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void upleft(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x-1,j=y-1;i>=0&&j>=0;i--,j--) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x-1,j=y-1;i>=0&&j>=0;i--,j--) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
void upright(int x, int y, char turn) {
char oppo;
if(oppo=='B') {
oppo='W';
}
else {
oppo='B';
}
bool check=false;
for(i=x-1,j=y+1;i>=0&&j<8;i--,j++) {
if(arr[i][j]==turn) {
check=true;break;
}
if(arr[i][j]=='_') {
check=false;break;
}
}
if(check==true) {
for(i=x-1,j=y+1;i>=0&&j<8;i--,j++) {
if(arr[i][j]==turn) {
break;
}
arr[i][j]=turn;
}
}
}
//--------------------------------------------------------
int main() {
for(i=0;i<n;i++) {
for(j=0;j<n;j++) {
cin >> arr[i][j];
}
}
// cin >> x >> y;
// arr[x][y]='B';
// right(x,y,'B');
// left(x,y,'B');
// down(x,y,'B');
// up(x,y,'B');
// downright(x,y,'B');
// downleft(x,y,'B');
// upleft(x,y,'B');
// upright(x,y,'B');
int turn = 1;
char c;
while(1) {
if(isfull()==true){break;}
cin >> x >> y; //x is height, y is <-->
if(x==-1&&y==-1) {
break;
}
if(turn%2==1||turn%2==-1){c='B';}
if(turn%2==0){c='W';}
arr[x][y]=c;
right(x,y,c);
left(x,y,c);
down(x,y,c);
up(x,y,c);
downright(x,y,c);
downleft(x,y,c);
upleft(x,y,c);
upright(x,y,c);
turn++;
}
//black first turn(1), white second turn(2)
show();
result();
return 0;
}