import os
import sys
# 请在此输入您的代码
def fun(big_list, j, k):
count = 0
try:
if big_list[j - 1][k] == 1:
count += 1
except:
pass
try:
if big_list[j - 1][k - 1] == 1:
count += 1
except:
pass
try:
if big_list[j - 1][k + 1] == 1:
count += 1
except:
pass
try:
if big_list[j][k - 1] == 1:
count += 1
except:
pass
try:
if big_list[j][k + 1] == 1:
count += 1
except:
pass
try:
if big_list[j + 1][k - 1] == 1:
count += 1
except:
pass
try:
if big_list[j + 1][k] == 1:
count += 1
except:
pass
try:
if big_list[j + 1][k + 1] == 1:
count += 1
except:
pass
return count
n, m = map(int, input().split())
list_big = []
for i in range(n):
list_big.append(list(map(int, input().split())))
j, k = 0, 0
list_input = []
for j in range(n):
list0 = []
for k in range(m):
if list_big[j][k] == 1:
list0.append(str(9))
continue
count = fun(list_big, j, k)
list0.append(str(count))
list_input.append(list0)
for item in list_input:
str0 = " ".join(i for i in item)
print(str0)
这个是我的输出结果