题目地址:http://vjudge.net/problem/UVA-11520
从A开始放,看看上下左右,依次顺延
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=a;i<=(b);++i)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define inside(x,y) (x>=0&&x<n&&y>=0&&y<n)
const int maxn=10+3,dx[]={0,0,1,-1},dy[]={1,-1,0,0};
int Gird[maxn][maxn],n;
void solve(){REP(i,0,n-1) REP(j,0,n-1) if(Gird[i][j]==-1){int p=0; for(;;){bool ok=true;REP(k,0,3) if(inside(i+dx[k],j+dy[k])){if(p==Gird[i+dx[k]][j+dy[k]]) p++,ok=false;}if(ok) break;}Gird[i][j]=p;}
}
int main(int argc, char const *argv[])
{int T,kase=0; scanf("%d",&T);while(T--){char ch; scanf("%d",&n);REP(i,0,n-1) REP(j,0,n-1) {do{ch=getchar();}while(ch!='.'&&!isalpha(ch));Gird[i][j]=ch=='.'?-1:ch-'A';}solve();printf("Case %d:\n",++kase);REP(i,0,n-1) REP(j,0,n-1) printf("%c%s", Gird[i][j]+'A',j==n-1?"\n":"");}return 0;
}