#include <iostream>
2023-01-01 17:21:17
发布于:北京
#include <iostream>
using namespace std;
int main(void)
{
int m, n;
cin >> m >> n;
char **a = new char [m + 1];
for (int i = 0; i < m; i++)
{
a[i] = new char[n];
cin >> a[i];
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if (a[i][j] == '')
{
continue;
}
int temp = 0;
for (int _i = i - 1; _i <= i + 1; _i++)
{
if (_i < 0 || _i > m - 1)
{
continue;
}
for (int _j = j - 1; _j <= j + 1; _j++)
{
if (_j < 0 || _j > n - 1)
{
continue;
}
if (a[_i][_j] == '*')
{
temp++;
}
}
}
a[i][j] = 48 + temp;
}
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
cout << a[i][j];
}
cout << endl;
}
return 0;
}
|
|
|
|
|
|
|
| |
|---|---|
| | | | |
|---|---|
| | | | |
|---|---|
| | | | |
|---|---|
| | | | |
|---|---|
| | | | |
|---|---|
| | | | |
|---|---|
| | |
这里空空如也
有帮助,赞一个