#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <cctype>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <map>
#include <stack>
#include <list>
#include <iomanip>
using namespace std;
///
#define INF 0xffffff7
#define maxn 10010
///
int rows, cols;
char maze[110][110];
int drow[] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dcol[] = { 0, 1, 1, 1, 0,-1, -1, -1};
int cnt(int posr, int posc)
{
int sum(0);
//上
int i;
for (i = 0; i < 8; i++)
{
int tempRow = posr + drow[i];
int tempCol = posc + dcol[i];
if (tempRow <= rows && tempRow > 0 && tempCol <= cols && tempCol > 0)
{
if (maze[tempRow][tempCol] == '*')
{
sum++;
}
}
}
return sum;
}
int main()
{
///
int i, j;
int ncases(1);
while (1)
{
cin >> rows >> cols;
if (rows == 0 || cols == 0)
break;
if (ncases != 1)
{
cout << endl;
}
memset(maze, 0, sizeof(maze));
cout << "Field #" << ncases << ":" << endl;
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= cols; j++)
{
cin >> maze[i][j];
}
}
for (i = 1; i <= rows; i++)
{
for (j = 1; j <= cols; j++)
{
if (maze[i][j] == '*')
{
cout << '*';
}
else
cout << cnt(i, j);
}
cout << endl;
}
ncases++;
}
///
return 0;
}
UVA 10189
最新推荐文章于 2020-03-13 17:48:37 发布