/**********************
* Author:fisty
* Data:2014-12-11
* uva11520
* 字典序最小
* *********************/
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define MAX_N 20
int n;
char G[MAX_N][MAX_N];
bool is_true(int i, int j, char c){
if((i > 0 && c == G[i-1][j]) ||
(i < n-1 && c == G[i+1][j]) ||
(j > 0 && G[i][j-1] == c) ||
(j < n-1 && G[i][j+1] == c))
return false;
return true;
}
int main(){
int t;
scanf("%d", &t);
for(int Kcase = 1;Kcase <= t; Kcase++){
scanf("%d", &n);
for(int i = 0;i < n; i++){
scanf("%s", G[i]);
}
for(int i = 0;i < n; i++){
for(int j = 0;j < n; j++){
char c;
if(G[i][j] == '.'){
for(c = 'A'; c <= 'Z'; c++){
//按字典序最小开始填
if(is_true(i,j,c)){
G[i][j] = c;
break;
}
}
}
}
}
printf("Case %d:\n", Kcase);
for(int i = 0;i < n; i++){
printf("%s\n", G[i]);
}
}
return 0;
}
uva11520 Fill the Square
最新推荐文章于 2020-05-04 10:49:13 发布