m, n = map(int, input().split())
a = []
for i in range(m):
row = list(input())
a.append(row)
for i in range(m):
for j in range(n):
if a[i][j] == '?':
a[i][j] = 0
elif a[i][j] == '*':
a[i][j] = 1
for i in range(m):
for j in range(n):
if a[i][j] == 1:
print('*', end='')
else:
count = 0
if i > 0 and j > 0 and a[i-1][j-1] == 1:
count += 1
if i > 0 and a[i-1][j] == 1:
count += 1
if i > 0 and j < n-1 and a[i-1][j+1] == 1:
count += 1
if j > 0 and a[i][j-1] == 1:
count += 1
if j < n-1 and a[i][j+1] == 1:
count += 1
if i < m-1 and j > 0 and a[i+1][j-1] == 1:
count += 1
if i < m-1 and a[i+1][j] == 1:
count += 1
if i < m-1 and j < n-1 and a[i+1][j+1] == 1:
count += 1
print(count, end='')
print('')
想了蛮久,最后还是用了笨办法来暴力做,直接用计数器原理把8个位置进行计数。这题我遇到的最大的问题在于索引边界的设立,就当发出来纪念一下。