ソースコード
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() {
vector<string> board(8);
for (int i = 0; i < 8; ++i) {
cin >> board[i];
}
int c;
cin >> c;
char color = (c == 0) ? 'b' : 'w';
string position;
cin >> position;
int x0 = position[0] - 'A';
int y0 = position[1] - '1';
int dx[] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dy[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
board[y0][x0] = color;
for (int i = 0; i < 8; ++i) {
vector<string> saved(board);
bool flipped = false;
int x = x0 + dx[i];
int y = y0 + dy[i];
while (x >= 0 && x < 8 && y >= 0 && y < 8) {
if (board[y][x] == '-') {
break;
}
else if (board[y][x] != color) {
board[y][x] = color;
}
else {
flipped = true;
break;
}
x += dx[i];
y += dy[i];
}
if (!flipped) {
board = saved;
}
}
for (int i = 0; i < 8; ++i) {
cout << board[i] << endl;
}
return 0;
}