Submission
Status:
PPPPPP-PPPPP-P----PP
Subtask/Task Score:
70/100
Score: 70
User: Some1258
Problemset: Othello
Language: cpp
Time: 0.002 second
Submitted On: 2026-07-29 09:56:10
#include<bits/stdc++.h>
using namespace std;
const int sze=8;
bool inside(int row, int col){
return row>=0&&row<sze&&col>=0&&col<sze;
}
void makemove(vector<string>& board, int row,int col, char player){
char opponent=(player=='B')?'W':'B';
const int dr[8]={-1,-1,-1,0,0,1,1,1};
const int dc[8]={-1,0,1,-1,1,-1,0,1};
board[row][col]=player;
for(int direction=0;direction<8;direction++){
int crow=row+dr[direction];
int ccol=col+dc[direction];
vector<pair<int,int>> piecestoflip;
while(inside(crow,ccol)&&board[crow][ccol]==opponent){
piecestoflip.push_back({crow,ccol});
crow+=dr[direction];
ccol+=dc[direction];
}
if(!piecestoflip.empty()&&inside(crow,ccol)&&board[crow][ccol]==player){
for(const auto& position : piecestoflip){
board[position.first][position.second]=player;
}
}
}
}
int main(){
vector<string> board(sze);
for(int row=0;row<sze;row++){
cin>>board[row];
}
char player='B';
int row,col;
while(cin>>row>>col){
if(row==-1&&col==-1){
break;
}
makemove(board,row,col,player);
player=(player=='B')?'W':'B';
}
int blackcount=0;
int whitecount=0;
for(const string& boardrow:board){
cout<<boardrow<<'\n';
for(char cell:boardrow){
if(cell=='B'){
blackcount++;
}else if(cell=='W'){
whitecount++;
}
}
}
if(blackcount>whitecount){
cout<<"black wins";
}else if(whitecount>blackcount){
cout<<"white wins";
}else{
cout<<"draw";
}
}