题解
2024-11-17 09:16:51
发布于:浙江
1阅读
0回复
0点赞
def cnt_mines(fld, r, c, n, m):
dirs = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]
count = 0
for dr, dc in dirs:
nr, nc = r + dr, c + dc
if 0 <= nr < n and 0 <= nc < m and fld[nr][nc] == '*':
count += 1
return count
def main():
n, m = map(int, input().split())
fld = [input().strip() for _ in range(n)]
res = [[''] * m for _ in range(n)]
for i in range(n):
for j in range(m):
if fld[i][j] == '?':
res[i][j] = str(cnt_mines(fld, i, j, n, m))
else:
res[i][j] = fld[i][j]
for row in res:
print(''.join(row))
if name == "main":
main()
全部评论 1
4天前 来自 浙江
0
有帮助,赞一个