算法竞赛入门经典训练指南打卡
题目链接:UVA 11520
思路
使用暴力枚举的方法查看即可,没有什么难的
代码如下:
#include <iostream>
#define ton(i , n) for(int i = 0 ; i < n ; ++ i)
using namespace std ;
char letter[15][15] ;
int main(){
int t , k = 1 ;
cin >> t ;
while (t --){
int n ;
cin >> n ;
ton(i , n)
ton(j , n)
cin >> letter[i][j] ; //输入
ton(i , n)
ton(j , n)
if(letter[i][j] == '.'){ //如果是‘.’,则需要我们填充大写字母
for (char a = 'A' ; a <= 'Z' ; ++ a){ //从A到Z依次尝试是否可以填充
bool check = true ;
if(i > 0 && a == letter[i - 1][j])
check = false ;
if(i < n - 1 && a == letter[i + 1][j])
check = false ;
if(j > 0 && a == letter[i][j - 1])
check = false ;
if(j < n - 1 && a == letter[i][j + 1])
check = false ;
if(check){
letter[i][j] = a ;
break ;
}
}
}
cout << "Case " << k ++ << ":" << endl ;
ton(i , n){
ton(j , n)
cout << letter[i][j] ; //输出
cout << endl ;
}
}
return 0 ;
}