ソースコード
#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'};
const int dh[8] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dw[8] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int n = 8;
vector<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(i, j)) 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] = bw[c]; return true;
}
}
int main() {
for (auto &e : s) cin >> e;
cin >> c;
int h, w; tie(h, w) = input();
for (int k = 0; k < 8; k++) {
dfs(h + dh[k], w + dw[k], dh[k], dw[k]);
}
s[h][w] = bw[c];
for (auto &e : s) cout << e << '\n';
return 0;
}