#include<iostream>
bool inBounds(long x,long y, long highX,long highY)
{
return ((x>0)&&(x<=highX)&&(y>0)&&(y<=highY));
}
int main()
{
long n,m,mines,field;
char input[1001][101],tmp;
field=1;
while ((std::cin>>n>>m)&&((n!=0)||(m!=0)))
{
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++)
{
std::cin>>tmp;
while(tmp=='\n')
std::cin>>tmp;
input[x][y]=tmp;
}
std::cout<<std::endl<<std::endl;
std::cout<<"Field #"<<field<<":"<<std::endl;
field++;
for (int x=1; x<=n; x++)
{
for (int y=1; y<=m; y++)
{
if (input[x][y]=='.')
{
mines=0;
if ((inBounds(x+1,y,n,m))&&(input[x+1][y]=='*'))
mines++;
if ((inBounds(x-1,y,n,m))&&(input[x-1][y]=='*'))
mines++;
if ((inBounds(x,y+1,n,m))&&(input[x][y+1]=='*'))
mines++;
if ((inBounds(x,y-1,n,m))&&(input[x][y-1]=='*'))
mines++;
if ((inBounds(x+1,y+1,n,m))&&(input[x+1][y+1]=='*'))
mines++;
if ((inBounds(x+1,y-1,n,m))&&(input[x+1][y-1]=='*'))
mines++;
if ((inBounds(x-1,y-1,n,m))&&(input[x-1][y-1]=='*'))
mines++;
if ((inBounds(x-1,y+1,n,m))&&(input[x-1][y+1]=='*'))
mines++;
std::cout<<mines;
}
else
std::cout<<"*";
}
std::cout<<std::endl;
}
}
} |