全部评论 5

  • 《114》

    2024-04-08 来自 浙江

    2
  • qwq

    6天前 来自 浙江

    0
  • n, m = map(int, input().split())
    grid = [list(input().strip()) for _ in range(n)]

    8 个方向

    dirs = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1), (0, 1),
    (1, -1), (1, 0), (1, 1)
    ]

    for i in range(n):
    for j in range(m):
    if grid[i][j] == '':
    continue
    cnt = 0
    for dx, dy in dirs:
    ni, nj = i + dx, j + dy
    if 0 <= ni < n and 0 <= nj < m:
    if grid[ni][nj] == '
    ':
    cnt += 1
    grid[i][j] = str(cnt)

    输出

    for row in grid:
    print(''.join(row))

    2026-01-15 来自 广东

    0
  • 发我去微软推哦怕立刻脚后跟范德萨自行车v吧

    2025-03-16 来自 上海

    0
  • 需要处理边界情况,可以在访问某个格子的周围格子时,先判断该格子是否在边界内,然后再进行访问

    2024-04-07 来自 浙江

    0
    • 加了,错了更多了😓

      2024-04-07 来自 浙江

      0
    • 就是边界问题,j-1的时候索引为负数,就会出问题。

      2024-04-07 来自

      0
    • 同时,i-1的时候因为是空字符串,也会索引超出。

      2024-04-07 来自

      0
暂无数据

提交答案之后,这里将显示提交结果~

首页