#include <cstdio> #define ok(p,q) p>0 && p<=n && q>0 && q<=m && a[p][q]=='*' //用宏简化代码 int n,m,x; char a[101][101]; int main() { scanf("%d%d",&n,&m); while (n!=0){ printf ("Field #%d:\n",++x); getchar(); for (int i=1;i<=n;++i,getchar()) for (int j=1;j<=m;++j) a[i][j]=getchar(); for (int i=1;i<=n;++i,putchar('\n')) for (int j=1;j<=m;++j){ if (a[i][j]=='*'){ //是雷直接输出 putchar('*'); continue; } a[i][j]='0'; //直接用ascii码操作 if (ok(i-1,j-1)) ++a[i][j]; if (ok(i-1,j)) ++a[i][j]; if (ok(i-1,j+1)) ++a[i][j]; if (ok(i,j-1)) ++a[i][j]; if (ok(i,j+1)) ++a[i][j]; if (ok(i+1,j-1)) ++a[i][j]; if (ok(i+1,j)) ++a[i][j]; if (ok(i+1,j+1)) ++a[i][j]; putchar(a[i][j]); } scanf("%d%d",&n,&m); if (n) putchar('\n'); //惨痛的教训,最后一个矩阵后不加空行 } return 0; }
3
5
2015
5
2015