Problem:


Score : 200 points

Problem Statement

You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).

. stands for an empty square, and # stands for a square containing a bomb.  

Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.  

Print the strings after the process.  

Constraints

1 \leq H,W \leq 50

S_i is a string of length W consisting of # and ..

Input

Input is given from Standard Input in the following format:  

H W
S_1
:
S_H

Output

Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).  

Sample Input 1

3 5
.....
.#.#.
.....

Sample Output 1

11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.  

Sample Input 2

3 5
#####
#####
#####

Sample Output 2

#####
#####
#####

It is possible that there is no empty square.  

Sample Input 3

6 6
#####.
#.#.##
####.#
.#..#.
#.##..
#.#...

Sample Output 3

#####3
#8#7##
####5#
4#65#2
#5##21
#4#310



Sample input:
3 5
.....
.#.#.
.....


Sample output:
11211
1#2#1
11211

Submission status: Wrong Answer

Solution code:
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    H,W = list(map(int,_in[0].split(' ')))  # type:list(int)
    S_arr = []
    for i in range(H):
        _ = list(_in[i+1])   # type:str
        S_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    num_arr = [[None]*W for i in range(H)]
    for i in range(H):
        for j in range(W):
            if S_arr[i][j] == '#':
                num_arr[i][j] = '#'
            else:
                cnt = 0
                try: cnt += 1 if S_arr[i-1][j-1]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i-1][j]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i-1][j+1]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i][j-1]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i][j+1]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i+1][j-1]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i+1][j]=='#' else 0
                except: pass
                try: cnt += 1 if S_arr[i+1][j+1]=='#' else 0
                except: pass
                num_arr[i][j] = str(cnt)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    for num in num_arr:
        print(''.join(num))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]

for i in range(H):
    for j in range(W):
        if s[i][j] == '.':
            count = 0
            for dx, dy in (
                (-1,1), (0,1), (1,0),
                (-1,0), (0,0), (0,1),
                (-1,-1),(0,-1),(1,-1)
            ):
                now_x, now_y = i+dx, j+dy
                if 0 <= now_x and 0 <= now_y and now_x <= H-1 and now_y <= W-1 and s[now_x][now_y] == "#":
                    count += 1
            s[i][j] = str(count)

for i in range(H):
    print(''.join(s[i]))

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
  
dx = [1, 1,  1, 0,  0, -1, -1, -1]
dy = [1, 0, -1, 1, -1,  1,  0, -1]

for h, row in enumerate(S):
  for w, i in enumerate(row):
    if i == '.':
      S[h][w] = 0
    if i == '#':
      for x, y in zip(dx, dy):
        if 0 <= x+w < W and 0 <= y+h < H:
          if S[y+h][x+w] == '#':
            continue
          elif S[y+h][x+w] == '.':
            S[y+h][x+w] = 1
          else:
            S[y+h][x+w] += 1
            
print(S)

Submission status: Wrong Answer

Solution code:
import numpy as np

H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]

dx = [1, 1,  1, 0,  0, -1, -1, -1]
dy = [1, 0, -1, 1, -1,  1,  0, -1]
for h, row in enumerate(S):
  for w, i in enumerate(row):
    if i == '#':
      for x, y in zip(dx, dy):
        if 0 <= x+w < W and 0 <= y+h < H:
          if S[y+h][x+w] == '#':
            continue
          elif S[y+h][x+w] == '.':
            S[y+h][x+w] = 1
          else:
            S[y+h][x+w] += 1
            
print(S)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

print(s)
dx = [-1, 0, 1]
dy = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for d_x in dx:
                for d_y in dy:
                    if 0 <= i + d_x < h and 0 <= j + d_y < w and s[i + d_x][j + d_y] != '#':
                        if s[i + d_x][j + d_y] == '.':
                            s[i + d_x][j + d_y] = 1
                        else:
                            s[i + d_x][j + d_y] += 1
                    else:
                        continue

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            s[i][j] = 0

print(s)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

print(s)
dx = [-1, 0, 1]
dy = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for d_x in dx:
                for d_y in dy:
                    if 0 <= i + d_x < h and 0 <= j + d_y < w:
                        if s[i + d_x][j + d_y] != '#':
                            if s[i + d_x][j + d_y] == '.':
                                s[i + d_x][j + d_y] = 1
                            else:
                                s[i + d_x][j + d_y] += 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            s[i][j] = 0

print(s)

Submission status: Wrong Answer

Solution code:
# A
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]#(h,w)
mine=[[0 for i in range(w)]for j in range(h)]
# 8方向
# #(-1,1)  #(0,1)  #(1,1)
# #(-1,0)    (#)   #(1,0)
# #(-1,-1) #(0,-1) #(1,-1)

dx = [0, 1, 1, 1, 0, -1, -1, -1]
dy = [-1, -1, 0, 1, 1, 1, 0, -1 ]
# print(s,mine)
for i in range(h):
    for j in range(w):
        # print(i,j)
        if s[i][j] == "#":
            mine[i][j]="#"
            for k in range(len(dx)):
                nx = i + dx[k]
                ny = j + dy[k]
                # print("m:",nx,ny)
                if 0 <= nx < h and 0 <= ny < w:
                    if s[nx][ny] != "#":
                        mine[nx][ny] += 1
for i in mine:
    print(*i)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

print(s)
dx = [-1, 0, 1]
dy = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for d_x in dx:
                for d_y in dy:
                    if 0 <= i + d_x < h and 0 <= j + d_y < w:
                        if s[i + d_x][j + d_y] != '#':
                            if s[i + d_x][j + d_y] == '.':
                                s[i + d_x][j + d_y] = 1
                            else:
                                s[i + d_x][j + d_y] += 1

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            s[i][j] = 0

print(s)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

print(s)
dx = [-1, 0, 1]
dy = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            for d_x in dx:
                for d_y in dy:
                    if 0 <= i + d_x < h and 0 <= j + d_y < w:
                        if s[i + d_x][j + d_y] != '#':
                            if s[i + d_x][j + d_y] == '.':
                                s[i + d_x][j + d_y] = 1
                            else:
                                s[i + d_x][j + d_y] += 1

print(s)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[]
for i in range(h):
  s.append(list(input()))
for i in range(0,h):
  for j in range(0,w):
    if s[i][j]==".":
      count=0
      try:
        if s[i-1][j-1]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i-1][j]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i-1][j+1]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i][j-1]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i][j+1]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i+1][j-1]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i+1][j]=="#":
          count+=1
      except IndexError:
        pass
      try:
        if s[i+1][j+1]=="#":
          count+=1
      except IndexError:
        pass
      s[i][j]=count

for x in range(0,len(s)):
  for y in range(0,len(s[0])):
    if y!=len(s[0])-1:
      print(s[x][y],end="")
    else:
      print(s[x][y])

Submission status: Wrong Answer

Solution code:

def myAnswer(H:int,W:int,S:list) -> None:
   XY = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
   index = []
   ans = [[0]*W for _ in range(H)]
   print(ans)
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):
            ans[i][j] = "#"
            index.append([i,j])
   print(ans,index)
   for i,j in index:
      for x,y in XY:
         if(0 > (j + x) or (j + x) >= W or 0 > (i + y) or (i + y) >= H):
            continue
         elif(ans[y+i][x+j]== "#"):
            continue
         else:
            ans[y + i][x + j] += 1
   for a in ans:
      string = ""
      for s in a:
         string += str(s)
      print(string)

def modelAnswer(H:int,W:int,S:list) -> int:
   dx = [1,0,-1,0,1,-1,-1,1]
   dy = [0,1,0,-1,1,1,-1,-1]
   for i in range(H):
      for j in range(W):
         if(S[i][j] == "#"):continue

         num = 0
         for d in range(8):
            ni = i + dy[d]
            nj = j + dx[d]
            if(ni < 0 or H <= ni):continue
            if(nj < 0 or W <= nj):continue
            if(S[ni][nj] == "#"): num+=1
         
         S[i][j] = str(num )
   for s in S:
      ans = ""
      for a in s:
         ans += a
      print(ans)
def main():
   H,W = map(int,input().split())
   S = [list(input()) for _ in range(H)]
   myAnswer(H,W,S[:])
if __name__ == '__main__':
   main()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())

S=[input() for i in range(H)]
R=[[] for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j]=='#':
      R[i].append('#')
    else:
      cnt=0
      for k in range(max(0,i-1),min(H,i+2)):
        for h in range(max(0,j-1),min(W,j+2)):
          if S[k][h]=='#':
            cnt+=1
      R[i].append(cnt)

for i in range(H):
  print(*R[i])

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
X = [-1, 0, 1]
Y = [-1, 0, 1]

for i in range(h):
    for j in range(w):
        if S[i][j] == '.':
            count = 0
            for x in X:
                for y in Y:
                    try:
                        if S[i+x][j+y] == '#':
                            count += 1
                    except:
                        continue
        else:
            continue
        S[i][j] = count

for s in S:
    print(''.join(map(str, s)))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())

S = [list(input()) for i in range(H)]

for line in S:
    line.insert(0, ".")
    line.insert(-1, ".")
S.insert(0, ["."]*(W+2))
S.insert(-1, ["."]*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == ".":
            count = S[i-1][j-1:j+2].count("#") + S[i][j-1:j+2].count("#") + S[i+1][j-1:j+2].count("#")
            S[i][j] = count

for i in range(1, H+1):
    for j in range(1, W+1):
        print(S[i][j], end="")
    print("")

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [[i for i in input()] for _ in range(h)]
count = 0
if h==1 and w==1:
    if s[0][0]=='#':
        print('#')
    else:
        print(0)
    exit(0)
if h==1:
    for j in range(w):
        if s[0][j]=='.':
            if j == 0:
                if s[0][j+1]=='#':
                    count += 1
                    s[0][j]=str(count)
                    count=0
            elif j == w-1:
                if s[0][j-1]=='#':
                    count += 1
                    s[0][j]=str(count)
                    count=0
            else:
                if s[0][j+1]=='#':
                    count += 1
                if s[0][j-1]=='#':
                    count += 1
                s[0][j]=str(count)
                count=0
    print(''.join(s[0]))
    exit(0)
if w==1:
    for i in range(h):
        if s[i][0]=='.':
            if i == 0:
                if s[i+1][0]=='#':
                    count += 1
                    s[i]=str(count)
                    count=0
            elif i == h-1:
                if s[i-1][0]=='#':
                    count += 1
                    s[i]=str(count)
                    count=0
            else:
                if s[i+1][0]=='#':
                    count += 1
                if s[i-1][0]=='#':
                    count += 1
                s[i][0]=str(count)
                count=0
    for i in range(h):
        print(''.join(s[i][0]))
    exit(0)

for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            if i == 0:
                if j == 0:
                    if s[i][j+1]=='#':
                        count+=1
                    if s[i+1][j]=='#':
                       count+=1
                    if s[i+1][j+1]=='#':
                        count+=1
                    s[i][j]=str(count)
                    count = 0
                elif j == w-1:
                    if s[i][j-1]=='#':
                        count+=1
                    if s[i+1][j]=='#':
                        count+=1
                    if s[i+1][j-1]=='#':
                        count+=1
                    s[i][j]=str(count)
                    count = 0
                else:
                    if s[i][j-1]=='#':
                        count+=1
                    if s[i][j+1]=='#':
                        count+=1
                    for k in range(3):
                        if s[i+1][j-1+k]=='#':
                            count+=1
                    s[i][j]=str(count)
                    count = 0
            elif i == h-1:
                if j == 0:
                    if s[i][j+1]=='#':
                        count+=1
                    if s[i-1][j]=='#':
                        count+=1
                    if s[i-1][j+1]=='#':
                        count+=1
                    s[i][j]=str(count)
                    count = 0
                elif j == w-1:
                    if s[i][j-1]=='#':
                        count+=1
                    if s[i-1][j]=='#':
                        count+=1
                    if s[i-1][j-1]=='#':
                        count+=1
                    s[i][j]=str(count)
                    count = 0
                else:
                    if s[i][j-1]=='#':
                        count+=1
                    if s[i][j+1]=='#':
                        count+=1
                    for k in range(3):
                        if s[i-1][j-1+k]=='#':
                            count+=1
                    s[i][j]=str(count)
                    count = 0
            else:
                if j==0:
                     if s[i+1][j]=='#':
                         count+=1
                     if s[i-1][j]=='#':
                         count+=1
                     for k in range(3):
                         if s[i-1+k][j+1]=='#':
                             count+=1
                     s[i][j]=str(count)
                     count = 0
                elif j==w-1:
                    if s[i+1][j]=='#':
                        count+=1
                    if s[i-1][j]=='#':
                        count+=1
                    for k in range(3):
                        if s[i-1+k][j-1]=='#':
                            count+=1
                    s[i][j]=str(count)
                    count = 0
                else:
                    if s[i][j-1]=='#':
                        count+=1
                    if s[i][j+1]=='#':
                        count+=1
                    for k in range(3):
                        if s[i+1][j-1+k]=='#':
                            count+=1
                        if s[i-1][j-1+k]=='#':
                            count+=1

                    s[i][j]=str(count)
                    count = 0
for i in range(h):
    print(''.join(s[i]))

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
L=[[0 for i in range(W)]for j in range(H)]
for i in range (H):
  L[i]=list(input())

for a in range(H):
    for b in range(W):
        if L[a][b]=='.':
             num=0
             for k in range(-1,2):
                 for l in range(-1,2):
                    if 0<=a+k<=H-1 and 0<=b+l<=W-1 and L[a+k][b+l]=='#':
                        num+=1
             L[a][b]=num
    print(*L[a])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    S[i] = list(input())
for i in range(H):
    for j in range(W):
        if (S[i][j] == '.'):
            count = 0
            for a in range(-1,2):
                for b in range(-1,2):
                    if(0<=i+a<=H-1 and 0<=j+b<=W-1):
                        if(S[i+a][j+b] == '#'):
                            count += 1
            S[i][j] = count
    print(*S[i])

Submission status: Wrong Answer

Solution code:
H,W = map(int,input('H W=').split())
S = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    S[i] = list(input('S='))
for i in range(0,H):
    for j in range(0,W):
        if (S[i][j] == '.'):
            count = 0
            for a in range(-1,2):
                for b in range(-1,2):
                    if(0<=i+a<=H-1 and 0<=j+b<=W-1):
                        if(S[i+a][j+b] == '#'):
                            count += 1
            S[i][j] = count
    print(S[i])

Submission status: Wrong Answer

Solution code:
def check_current_posi(s_i_list, h, w):
  _height = len(s_i_list)
  _width = len(s_i_list[0])
  if h == -1 or w == -1 or h >= _height or w >= _width:
    return False

  else:
    if s_i_list[h][w] == "#":
      # bomb
      return True

    else:
      # not bomb
      return False

# hとwは0から
def check_around_bomb_num(s_i_list, h, w):

  check_posi_h = h - 1
  check_posi_w = w - 1

  bomb_counter = 0

  for i in range(3):

    for j in range(3):

      if check_current_posi(s_i_list, check_posi_h, check_posi_w):
        bomb_counter += 1

      check_posi_w += 1

    check_posi_h += 1
    check_posi_w = w - 1
  
  return bomb_counter
      

# _input = [6, 6]
_input = list(map(int, input().split(" ")))

height = _input[0]
width = _input[1]

s_i_list = []

for i in range(height):
  _input_row = list(input())
  s_i_list.append(_input_row)

# s_i_list = [['#', '#', '#', '#', '#', '.'], ['#', '.', '#', '.', '#', '#'], ['#', '#', '#', '#', '.', '#'], ['.', '#', '.', '.', '#', '.'], ['#', '.', '#', '#', '.', '.'], ['#', '.', '#', '.', '.', '.']]

for row in range(height):
  for column in range(width):
    if s_i_list[row][column] == "#":
      continue

    s_i_list[row][column] = check_around_bomb_num(s_i_list, row, column)


print(s_i_list)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W = map(int,input().split())

S = [list(input()) for _ in range(H)]
point_list = np.array([['#']*W]*H)
dy = [0,0,1,1,1,-1,-1,-1]
dx = [1,-1,0,1,-1,0,1,-1]

for h in range(H):
  for w in range(W):
    count = 0
    for i in range(8):
      y = h+dy[i]
      x = w+dx[i]
      if y < 0 or y >= H or x < 0 or x >= W:
        continue
      if S[h][w] == '.' and S[y][x] == '#':
        count += 1
    if count != 0:
      point_list[h][w] = count

for j in range(H):
  print(''.join(point_list[j]))

Submission status: Wrong Answer

Solution code:
# AtCoder Beginner Contest 075
# B - Minesweeper
# https://atcoder.jp/contests/abc075/tasks/abc075_b
H, W, *S = open(0).read().split()
H, W = int(H), int(W)
S = [tuple(s) for s in S]
print(S)
ans = [[0]*W for _ in [0]*H]
dirs = [(-1, -1), (-1, 0), (-1, 1), (0, -1), (0, 1), (1, -1), (1, 0), (1, 1)]

for y, _s in enumerate(S):
    for x, s in enumerate(_s):
        if s == '#':
            ans[y][x] = '#'
            for dy, dx in dirs:
                if 0 <= x + dx < W and 0 <= y + dy < H and S[y+dy][x+dx] != "#":
                    ans[y+dy][x+dx] += 1

for a in ans:
    print(''.join(map(str, a)))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[input() for i in range(h)]
a=[[0]*w for i in range(h)]

if h==1 and w==1:
  if s[0]=="#":
    print("#")
  else:
    print(0)
elif h==1 and w>1:
  for i in range(w):
    t=0
    if i==0:
      if s[0][i+1]=="#":t+=1
    elif 0<i<w-1:
      if s[0][i+1]=="#":t+=1
      if s[0][i-1]=="#":t+=1
    elif i==w-1:
      if s[0][i-1]=="#":t+=1
    if s[0][i]=="#":
      a[0][i]="#"
    else:
      a[0][i]=t
  tt=""
  for aa in a:
    for aaa in aa:
      tt+=str(aaa)
  print(str(tt))

elif w==1 and h>1:
  for i in range(h):
    t=0
    if i==0:
      if s[i+1]=="#":t+=1
    elif 0<i<w-1:
      if s[i+1]=="#":t+=1
      if s[i-1]=="#":t+=1
    elif i==h-1:
      if s[i-1]=="#":t+=1
    if s[i]=="#":
      a[i][0]="#"
    else:
      a[i][0]=t
  for aa in a:
    print(*aa)
elif w>1 and h>1:
  for i in range(h):
    for j in range(w):
      t=0
      if i==0:
        if j==0:
          if s[i][j+1]=="#":t+=1
          if s[i+1][j+1]=="#":t+=1
          if s[i+1][j]=="#":t+=1
        elif 0<j<w-1:
          if s[i][j+1]=="#":t+=1
          if s[i+1][j+1]=="#":t+=1
          if s[i+1][j]=="#":t+=1
          if s[i+1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1        
        elif j==w-1:
          if s[i+1][j]=="#":t+=1
          if s[i+1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1 
      elif 0<i<h-1:
        if j==0:
          if s[i-1][j]=="#":t+=1
          if s[i-1][j+1]=="#":t+=1
          if s[i][j+1]=="#":t+=1
          if s[i+1][j+1]=="#":t+=1
          if s[i+1][j]=="#":t+=1
        elif 0<j<w-1:
          if s[i][j+1]=="#":t+=1
          if s[i+1][j+1]=="#":t+=1
          if s[i+1][j]=="#":t+=1
          if s[i+1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1
          if s[i-1][j-1]=="#":t+=1
          if s[i-1][j]=="#":t+=1
          if s[i-1][j+1]=="#":t+=1
        elif j==w-1:
          if s[i+1][j]=="#":t+=1
          if s[i+1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1
          if s[i-1][j-1]=="#":t+=1
          if s[i-1][j]=="#":t+=1      
      elif i==h-1:
        if j==0:
          if s[i][j+1]=="#":t+=1
          if s[i-1][j+1]=="#":t+=1
          if s[i-1][j]=="#":t+=1
        elif 0<j<w-1:
          if s[i][j+1]=="#":t+=1
          if s[i-1][j+1]=="#":t+=1
          if s[i-1][j]=="#":t+=1
          if s[i-1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1        
        elif j==w-1:
          if s[i-1][j]=="#":t+=1
          if s[i-1][j-1]=="#":t+=1
          if s[i][j-1]=="#":t+=1
      if s[i][j]=="#":
        a[i][j]="#"
      else:
        a[i][j]=t
  for aa in a:
    tt=""
    for aaa in aa:
      tt+=str(aaa)
    print(tt)

Submission status: Wrong Answer

Solution code:
import pprint
h,w = map(int,input().split())
s = [["!"]*(w+2)] + [list("!" + input() + "!") for _ in range(h)] + [["!"]*(w+2)]
next = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] == "#":
            continue
        count = 0
        for d1,d2 in next:
            count += (s[i + d1][j+d2] == "#")
        s[i][j] = str(count)
ans = []
for k in s:
    k = [x for x in k if not x =="!"]
    if k:
        ans.append(k)
for adf in ans:
    print(" ".join(adf))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
mp = []
for i in range(H):
    mp.append('.' + input() + '.')
mp_num = [[0] * (W+2) for i in range(H+2)]

mp.insert(0, '.'*(W+2))
mp.insert(-1, '.'*(W+2))

for i in range(1, H+1):
    for j in range(1, W+1):
        if mp[i][j] == '#':
            mp_num[i-1][j-1] += 1
            mp_num[i-1][j] += 1
            mp_num[i-1][j+1] += 1
            mp_num[i][j-1] += 1
            mp_num[i][j+1] += 1
            mp_num[i+1][j-1] += 1
            mp_num[i+1][j] += 1
            mp_num[i+1][j+1] += 1

for i in range(1, H+1):
    for j in range(1, W+1):
        if mp[i][j] == '#':
            mp_num[i][j] = '#'

for i in range(H):
    tmp = [str(a) for a in mp_num[i+1]]
    print(''.join(tmp[1:W+1]))

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
A = []
for i in range(H):
  A.append(list(input()))

for h in range(H):
  for w in range(W):
    if A[h][w] == "#":
      print("#",end="")
    elif A[h][w] == ".":
      c = 0 
      for i in range(-1,2):
        for j in range(-1,2):
          if 0<=h+i<=h and 0<=w+j<=w and A[h+i][w+j]=="#":
            c+=1
      print(c,end="")
  print("")

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

dxy=[(-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)]
def bombcount(hi,wi):
  cnt=0
  for x,y in dxy:
    
      
    if 0<=hi+x<=h-1 and 0<=wi+y<=w-1:
      if s[hi+x][wi+y]=="#":
        print(x,y)
        cnt+=1
  return cnt
      
for i in range(h):
  for j in range(w):
    
    
    if s[i][j]==".":
      s[i][j]=str(bombcount(i,j))
      
for i in range(h):
  print("".join(s[i]))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]

dx=[-1,-1,-1,0,0,1,1,1]
dy=[-1,0,1,-1,1,-1,0,1]
def bombcount(hi,wi):
  cnt=0
  for x in range(-1,2):
    for y in range(-1,2):
      
      if 0<=hi+x<h-1 and 0<=wi+y<w-1:
        if s[hi+x][wi+y]=="#":
          cnt+=1
  return cnt
      
for i in range(h):
  for j in range(w):
    
    if s[i][j]=="#":
      continue
    else:
      s[i][j]=str(bombcount(i,j))
      
for i in range(h):
  print("".join(s[i]))

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = []
for _ in range(H):
    S.append(input())

ans = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] = "#"
            if j-1 >= 0 and ans[i][j-1] != "#":
                ans[i][j-1] += 1
            if j-1 >= 0 and i-1 >= 0 and ans[i-1][j-1] != "#":
                ans[i-1][j-1] += 1
            if j-1 >= 0 and i+1 <= H-1 and ans[i+1][j-1] != "#":
                ans[i+1][j-1] += 1

            if i-1 >= 0 and ans[i-1][j] != "#":
                ans[i-1][j] += 1
            if i+1 <= H-1 and ans[i+1][j] != "#":
                ans[i+1][j] += 1
            
            if j+1 <= W-1 and ans[i][j+1] != "#":
                ans[i][j+1] += 1
            if j+1 <= W-1 and i-1 >= 0 and ans[i-1][j+1] != "#":
                ans[i-1][j+1] += 1
            if j+1 <= W-1 and i+1 <= H-1 and ans[i+1][j+1] != "#":
                ans[i+1][j+1] += 1                        

for i in range(H):
    print(*ans[i])

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
x = [list(map(int, input().replace('.', '0').replace('#', '1'))) for _ in range(h)]
x1 = [[0]*(w+2)]*2
for i in range(h):
    x1.insert(i+1, [0]+x[i]+[0])

x2 = [['#']*w]*h

for i in range(h):
    for j in range(w):
        if x[i][j] == 1:
            continue
        else:
            x2[i][j] = sum(x1[i][j-1:j+2])+sum(x1[i+1][j-1:j+2])+sum(x1[i+2][j-1:j+2])

for i in x2:
    print(''.join(map(str, i)).replace('0', '#'))

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
x = [list(map(int, input().replace('.', '0').replace('#', '1'))) for _ in range(h)]
x1 = [[0]*(w+2)]*2
for i in range(h):
    x1.insert(i+1, [0]+x[i]+[0])

x2 = [['#']*w]*h

for i in range(h):
    for j in range(w):
        if x[i][j] == 1:
            continue
        else:
            x2[i][j] = sum(x1[i][j-1:j+2])+sum(x1[i+1][j-1:j+2])+sum(x1[i+2][j-1:j+2])
            print('hoge')

for i in x2:
    print(''.join(map(str, i)).replace('0', '#'))

Submission status: Wrong Answer

Solution code:
def nyu():
    H,W = map(int,input().split())
    S = [list(input()) for i in range(H)] 
    return S,H,W

def check(S,H,W):

    for h in range(H):
        for w in range(W):
            if S[h][w] != "#":
                if h !=0 :
                    if S[h-1][w] == "#":
                        S[h][w] +=1
                if h !=H-1 :
                    if S[h+1][w] == "#":
                        S[h][w] +=1
                if w !=0 :
                    if S[h][w-1] == "#":
                        S[h][w] +=1
                if w !=W-1 :
                    if S[h][w+1] == "#":
                        S[h][w] +=1
#右斜め
                if h !=H-1  and w !=W-1:                    
                    if S[h+1][w+1] == "#":
                        S[h][w] +=1
                if h != 0  and w !=W-1:                    
                    if S[h-1][w+1] == "#":
                        S[h][w] +=1
#左斜め下　左斜め上
                if h !=H-1  and w !=0:                    
                    if S[h+1][w-1] == "#":
                        S[h][w] +=1

                if h != 0  and w !=0:                    
                    if S[h-1][w-1] == "#":
                        S[h][w] +=1

 #   for a in S:
 #       print(*a)
    print(S)

def convert(S,H,W):
    
    for h in range(H):
        for w in range(W):
            if S[h][w]==".":
                S[h][w] = 0
    return S




S,H,W = nyu()
S =convert(S,H,W)
check(S,H,W)