ソースコード
#include <bits/stdc++.h>
using namespace std;
pair<int, int> input() {
char a, b;
cin >> a >> b;
return make_pair(b - '1', a - 'A');
}
const char bw[2] = {'b', 'w'};
constexpr int n = 8;
string s[n];
int c;
bool check (int i, int j) {
return (0 <= i and i < n and 0 <= j and j < n);
}
bool dfs (int i, int j, int di, int dj) {
if (not check) return false;
if (s[i][j] == '-') return false;
if (s[i][j] == bw[c]) return true;
if (dfs(i + di, j + dj, di, dj)) {
s[i][j] = c; return true;
}
}
int main() {
for (auto &e : s) cin >> e;
cin >> c;
int h, w; tie(h, w) = input();
dfs(h, w + 1, 0, 1);
dfs(h + 1, w, 1, 0);
dfs(h, w - 1, 0, -1);
dfs(h - 1, w, -1, 0);
s[h][w] = bw[c];
for (auto &e : s) cout << e << '\n';
return 0;
}