纯暴力。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
const int maxn = 20;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
int T, n, kase = 0;
char str[maxn][maxn];
int main() {
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%s", str[i] + 1);
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= n; ++j) {
if(str[i][j] == '.') {
for(char ch = 'A'; ch != 'Z'; ++ch) {
bool ok = true;
for(int k = 0; k < 4; ++k) {
int nx = dx[k] + i, ny = dy[k] + j;
if(ch == str[nx][ny]) ok = false;
}
if(ok) {
str[i][j] = ch;
break;
}
}
}
}
}
printf("Case %d:\n", ++kase);
for(int i = 1; i <= n; ++i)
printf("%s\n", str[i] + 1);
}
return 0;
}