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:
H, W = map(int, input().split())
S = [input() for _ in range(H)]

ans = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            ans[i][j] += 11

#入力が1列の場合
if W == 1:
    for i in range(H-1):
        if ans[i+1][0] > 10:
            ans[i][0] += 1
    for i in range(1, H):
        if ans[i-1][0] > 10:
            ans[i][0] += 1

    for i in range(H):
        if ans[i][0] > 10:
            ans[i][0] = "#"
        ans[i] = map(str, ans[i])
        ans[i] = "".join(ans[i])

    for a in ans:
        print(a)
    exit()


#横方向の確認
for i in range(H):
    for j in range(W - 1):
        if ans[i][j+1] > 10:
            ans[i][j] += 1
    for j in range(1, W):
        if ans[i][j-1] > 10:
            ans[i][j] += 1

#縦方向の確認
for j in range(1, W-1):
    for i in range(H-1):
        if ans[i+1][j-1] > 10:
            ans[i][j] += 1
        if ans[i+1][j] > 10:
            ans[i][j] += 1
        if ans[i+1][j+1] > 10:
            ans[i][j] += 1

    for i in range(1, H):
        if ans[i-1][j-1] > 10:
            ans[i][j] += 1
        if ans[i-1][j] > 10:
            ans[i][j] += 1
        if ans[i-1][j+1] > 10:
            ans[i][j] += 1

#j = 0
for i in range(H-1):
    if ans[i+1][0] > 10:
        ans[i][0] += 1
    if W > 2 and ans[i+1][1] > 10:
        ans[i][0] += 1
for i in range(1, H):
    if ans[i-1][0] > 10:
        ans[i][0] += 1
    if W > 2 and ans[i-1][1] > 10:
        ans[i][0] += 1

#j = W-1
for i in range(H-1):
    if ans[i+1][W-1] > 10:
        ans[i][W-1] += 1
    if ans[i+1][W-2] > 10:
        ans[i][W-1] += 1
for i in range(1, H):
    if ans[i-1][W-1] > 10:
        ans[i][W-1] += 1
    if ans[i-1][W-2] > 10:
        ans[i][W-1] += 1

for i in range(H):
    for j in range(W):
        if ans[i][j] > 10:
            ans[i][j] = "#"
    ans[i] = map(str, ans[i])
    ans[i] = "".join(ans[i])

for a in ans:
    print(a)

Submission status: Wrong Answer

Solution code:
h,w=map(int, input().split())
mat = []
mat.append(["."]*(w+2))
for i in range(h):
  mat.append(["."]+list(input())+["."])
mat.append(["."]*(w+2))
for y in range(1, h+1):
  for x in range(1, w+1):
    if mat[y][x] != "#":
      c = 0
      if mat[y-1][x-1] == "#":
        c += 1
      if mat[y-1][x] == "#":
        c += 1       
      if mat[y-1][x+1] == "#":
        c += 1      
      if mat[y][x-1] == "#":
        c += 1
      if mat[y][x+1] == "#":
        c += 1
      if mat[y+1][x-1] == "#":
        c += 1        
      if mat[y+1][x] == "#":
        c += 1        
      if mat[y+1][x+1] == "#":
        c += 1
      mat[y][x] = str(c)

for y in range(1, h+1):
  print(mat[y][1:w+1])

Submission status: Wrong Answer

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

s = [[0]*(W+2)]*(H+2)

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            s[i+1][j+1] = 9

for i in range(H):
    for j in range(W):
        if s[i+1][j+1] >= 9:
            s[i+0][j+0] += 1
            s[i+0][j+1] += 1
            s[i+0][j+2] += 1
            s[i+1][j+0] += 1
            s[i+1][j+1] += 1
            s[i+1][j+2] += 1
            s[i+2][j+0] += 1
            s[i+2][j+1] += 1
            s[i+2][j+2] += 1

for i in range(1,H+1):
    ans = ""
    for j in range(1,W+1):
        ans += str(s[i][j])
    print(ans)

Submission status: Wrong Answer

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

for i in range(H):
    grid[i] = input()
    s[i] = list(grid[i])

for h in range(H):
    for w in range(W):
        count = 0
        if s[h][w] == '.':
            try:
                if s[h-1][w-1] == '#':
                    count+=1
            except:
                None
            try:
                if s[h-1][w] == '#':
                    count+=1
            except:
                None
            try:
                if s[h-1][w+1] == '#':
                    count+=1
            except:
                None
            try:
                if s[h][w-1] == '#':
                    count+=1
            except:
                None
            try:
                if s[h][w+1] == '#':
                    count+=1
            except:
                None
            try:
                if s[h+1][w-1] == '#':
                    count+=1
            except:
                None
            try:
                if s[h+1][w] == '#':
                    count+=1
            except:
                None
            try:
                if s[h+1][w+1] == '#':
                    count+=1
            except:
                None
            if count > 0:
                s[h][w] = str(count)

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

Submission status: Wrong Answer

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

for i in range(H):
    grid[i] = input()
    s[i] = list(grid[i])

for h in range(H):
    for w in range(W):
        count = 0
        try:
            if s[h-1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w+1] == '#':
                count+=1
        except:
            None
        if count > 0:
            s[h][w] = str(count)

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

Submission status: Wrong Answer

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

for i in range(H):
    grid[i] = input()
    s[i] = list(grid[i])

for h in range(H):
    for w in range(W):
        count = 0
        try:
            if s[h-1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h-1][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h][w+1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w] == '#':
                count+=1
        except:
            None
        try:
            if s[h+1][w+1] == '#':
                count+=1
        except:
            None
        if count > 0:
            s[h][w] = str(count)

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

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
grid = [['.']*W for i in range(H)]
for i in range(H):
    grid[i] = input().split()

for h in range(H):
    for w in range(W):
        count = 0
        try:
            if grid[h-1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if grid[h-1][w] == '#':
                count+=1
        except:
            None
        try:
            if grid[h-1][w+1] == '#':
                count+=1
        except:
            None
        try:
            if grid[h][w-1] == '#':
                count+=1
        except:
            None
        try:
            if grid[h][w+1] == '#':
                count+=1
        except:
            None
        try:
            if grid[h+1][w-1] == '#':
                count+=1
        except:
            None
        try:
            if grid[h+1][w] == '#':
                count+=1
        except:
            None
        try:
            if grid[h+1][w+1] == '#':
                count+=1
        except:
            None
        if count > 0:
            grid[h][w] = str(count)

for h in range(H):
    print(' '.join(grid[h]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a, b = [], []
ans = 0
for _ in range(H):
    a += [0 if x == '.' else 1 for x in input()]
for i in range(H*W):
    if a[i] == 0:
        if i % W != 0: ans += a[i-1]
        if (i+1) % W != 0: ans += a[i+1]
        if i < (H-1)*W: ans += a[i+W]
        if i < (H-1)*W and i % W != 0: ans += a[i+W-1]
        if i < (H-1)*W and (i+1) % W != 0: ans += a[i+W+1]
        if W < i: ans += a[i-W]
        if i % W != 0 and W < i: ans += a[i-W-1]
        if W < i and (i+1) % W != 0: ans += a[i-W+1]
        b += [str(ans)]
        ans = 0
    else:
        b += ['#']
        
for i in range(H):
    print(''.join(b[W*i:W*(i+1)]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a, b = [], []
ans = 0
for _ in range(H):
    a += [0 if x == '.' else 1 for x in input()]
for i in range(H*W):
    if a[i] == 0:
        if i % H != 0: ans += a[i-1]
        if (i+1) % W != 0: ans += a[i+1]
        if i < (H-1)*W: ans += a[i+W]
        if i < (H-1)*W and i % H != 0: ans += a[i+W-1]
        if i < (H-1)*W and (i+1) % W != 0: ans += a[i+W+1]
        if W < i: ans += a[i-W]
        if i % H != 0 and W < i: ans += a[i-W-1]
        if W < i and (i+1) % W != 0: ans += a[i-W+1]
        b += [str(ans)]
        ans = 0
    else:
        b += ['#']
        
for i in range(H):
    print(''.join(b[W*i:W*(i+1)]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
a, b = [], []
ans = 0
for _ in range(H):
    a += [0 if x == '.' else 1 for x in input()]
for i in range(H*W):
    if a[i] == 0:
        if i-1 >= 0: ans += a[i-1]
        if (i+1) % W != 0: ans += a[i+1]
        if i < (H-1)*W: ans += a[i+W]
        if i < (H-1)*W and i-1 >= 0: ans += a[i+W-1]
        if i < (H-1)*W and (i+1) % W != 0: ans += a[i+W+1]
        if W < i: ans += a[i-W]
        if i-1 >= 0 and W < i: ans += a[i-W-1]
        if W < i and (i+1) % W != 0: ans += a[i-W+1]
        b += [str(ans)]
        ans = 0
    else:
        b += ['#']
        
for i in range(H):
    print(''.join(b[W*i:W*(i+1)]))

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
L = [[x if x=='#' else 0 for x in input()] for _ in range(H)]

for i in range(H):
  l = L[i]
  l_before=None
  l_after=None
  if i>0:
    l_before=L[i-1]
  if i<H-1:
    l_after=L[i+1]
    
  for j in range(W):
    if l[j] != '#':
      try:
        if l_before[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_before[j]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_before[j+1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l[j+1]=='#':
          l[j]+=1
      except:
        pass
      
      try:
        if l_after[j-1]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_after[j]=='#':
          l[j]+=1
      except:
        pass
      try:
        if l_after[j+1]=='#':
          l[j]+=1
      except:
        pass


for i in range(H):
  for j in range(W):
    print(str(L[i][j]),end='')
  else:
    print()

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())

dx = [1,1,1,0,-1,-1,-1,0]
dy = [0,1,-1,1,0,1,-1,-1]
ans = [[0] * (w + 2) for _ in range(h + 2)]

s = [input() for _ in range(h)]
for i in range(h):
    s[i] = '.' + s[i] + '.' 
s = ['.' * (w + 2)] + s + ['.' * (w + 2)] 

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            for A in range(8):
                if(s[i + dy[A]][j + dx[A]]=='#'):
                    ans[i][j] += 1
                    print(ans[i][j])

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i][j] == '.':
            print(ans[i][j],end='')
        else:
            print('#',end='')
    print()

Submission status: Wrong Answer

Solution code:
def p(h,w):
    try:
        S[h][w] += 1
    except:
        None

H,W = map(int,input().split())
S = [[0 if i == "." else "#" for i in input()] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            p(i+1, j)
            p(i+1, j+1)
            p(i+1, j-1)
            p(i-1, j)
            p(i-1, j+1)
            p(i-1, j-1)
            p(i, j+1)
            p(i, j-1)
        else:
            None
for k in S:
    a = list(map(str,k))
    print("".join(a))

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
gaze = ["W"+input()+"W" for _ in range(h)]
print(gaze)
gaze = ["W"*(w+2)]+gaze+["W"*(w+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        count = 0
        if gaze[i][j] == ".":
            if gaze[i-1][j-1] == "#":
                count += 1
            if gaze[i-1][j] == "#":
                count += 1
            if gaze[i-1][j+1] == "#":
                count += 1
            if gaze[i+1][j-1] == "#":
                count += 1
            if gaze[i+1][j] == "#":
                count += 1
            if gaze[i+1][j+1] == "#":
                count += 1
            if gaze[i][j-1] == "#":
                count += 1
            if gaze[i][j+1] == "#":
                count += 1
            gaze[i] = gaze[i][:j]+str(count)+gaze[i][j+1:]

s = "abcd"
print(gaze)

for i in range(1,h+1):
    for j in range(1,w+1):
        if j == w:
            print(gaze[i][j])
        else:
            print(gaze[i][j],end="")

Submission status: Wrong Answer

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

x = [1,-1,1,-1,0,0,1,-1]
y = [1,-1,0,0,1,-1,-1,1]
n_s = []
for i in range(h):
    n_l = []
    for j in range(w):
        cnt=0
        for k in range(8):
            print(i+x[k])
            print(j+y[k])
            if l[i][j]=="#":
                cnt = "#"
                break
            elif 0<=i+x[k]<h and 0<=j+y[k]<w:
                if l[i+x[k]][j+y[k]]=="#":
                    cnt+=1
            else:
                continue
        n_l.append(str(cnt))
    n_s.append(n_l)

for i in n_s:
    print("".join(i))

Submission status: Wrong Answer

Solution code:
# 20200612_yorukatsu_b.py
def canGo(h,w,y,x):
    if h==y and w==x:
        return False
    if h<0 or h>=H or w<0 or w>=W:
        return False
    if glid[h][w] == "#":
        return False
    return True

def search(h,w):
    dy=[-1,0,1]
    dx=[-1,0,1]
    if glid[h][w]=="#":
        for y in dy:
            for x in dx:
                if canGo(h+y,w+x,h,w):
                    mine[h+y][w+x]+=1

H,W = map(int,input().split())
glid =[]
for i in range(H):
    glid.append(list(input()))
# print(glid)
mine = [[0]*W for i in range(H)]
# print(mine)

for i in range(H):
    for j in range(W):
        search(i,j)
for i in mine:
    for j in i:
        print(j if j!=0 else "#",end="")
    print()

Submission status: Wrong Answer

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

l=[]
for i in range(H):
    l.append(list(input()))

for i in range(H):
    for j in range(W):
    # 地雷数のカウンタ
        c=0

    # '#'の場合はなにもしない
    if l[i][j]=='#':
        pass

    # '#'以外の場合
    else:
      # 左上
        if 0<i and 0<j and l[i-1][j-1]=='#':
            c+=1
      # 上
        if 0<i and l[i-1][j]=='#':
            c+=1
      # 右上
        if 0<i and j<W-1 and l[i-1][j+1]=='#':
            c+=1
      # 左
        if 0<j and l[i][j-1]=='#':
            c+=1
      # 右
        if j<W-1 and l[i][j+1]=='#':
            c+=1
      # 左下
        if i<H-1 and 0<j and l[i+1][j-1]=='#':
            c+=1
      # 下
        if i<H-1 and l[i+1][j]=='#':
            c+=1
      # 右下
        if i<H-1 and j<W-1 and l[i+1][j+1]=='#':
            c+=1

      # 地雷隣接数を記載
        l[i][j]=str(c)

# 出力
for i in range(H):
    print(''.join(l[i]))

Submission status: Wrong Answer

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

l=[]
for i in range(H):
    l.append(list(input()))

for i in range(H):
    for j in range(W):
    # 地雷数のカウンタ
        c=0

    # '#'の場合はなにもしない
    if l[i][j]=='#':
        pass

    # '#'以外の場合
    else:
      # 左上
      if 0<i and 0<j and l[i-1][j-1]=='#':
        c+=1
      # 上
      if 0<i and l[i-1][j]=='#':
        c+=1
      # 右上
      if 0<i and j<W-1 and l[i-1][j+1]=='#':
        c+=1
      # 左
      if 0<j and l[i][j-1]=='#':
        c+=1
      # 右
      if j<W-1 and l[i][j+1]=='#':
        c+=1
      # 左下
      if i<H-1 and 0<j and l[i+1][j-1]=='#':
        c+=1
      # 下
      if i<H-1 and l[i+1][j]=='#':
        c+=1
      # 右下
      if i<H-1 and j<W-1 and l[i+1][j+1]=='#':
        c+=1

      # 地雷隣接数を記載
      l[i][j]=str(c)

# 出力
for i in range(H):
    print(''.join(l[i]))

Submission status: Wrong Answer

Solution code:
print()

Submission status: Wrong Answer

Solution code:
H,W=[int(i) for i in input().split(" ")]
S=[input() for i in range(H)]


for k,v in enumerate(S):
  for kk,vv in enumerate(list(v)):
    checkTarget = []
    if vv == "#":
      print("#", end="" )
    else:
      if H==1 and W==1:
        print("." , end="")
        break
      if k == 0 and kk == 0:
        checkTarget = [                         
                                                   S[k][kk+1],
                                     S[k+1][kk], S[k+1][kk+1]]

      elif k == 0 and kk > 0 and kk < len(v)-1 and H==1:
        checkTarget = [ 
                        S[k][kk-1],             S[k][kk+1],
                        ]

      elif k == 0 and kk > 0 and kk < len(v)-1:
        checkTarget = [ 
                        S[k][kk-1],             S[k][kk+1],
                        S[k+1][kk-1], S[k+1][kk], S[k+1][kk+1]]
      elif k == 0 and kk == len(v)-1 and H==1:
        checkTarget = [ 
                        S[k][kk-1],             
                        ]

      elif k == 0 and kk == len(v)-1:
        checkTarget = [ 
                        S[k][kk-1],             
                        S[k+1][kk-1], S[k+1][kk]]
      elif k > 0 and k < len(S) -1 and kk==0 and W==1:
        checkTarget = [       S[k-1][kk],
                                         
                              S[k+1][kk]]

      elif k > 0 and k < len(S) -1 and kk==0:
        checkTarget = [       S[k-1][kk], S[k-1][kk+1],
                                         S[k][kk+1],
                              S[k+1][kk], S[k+1][kk+1]]

      elif k > 0 and k < len(S) -1 and kk==len(v)-1:
        checkTarget = [ S[k-1][kk-1],  S[k-1][kk],
                        S[k][kk-1],             
                        S[k+1][kk-1], S[k+1][kk]]

      elif k == len(S) -1 and kk == 0 and W==1:
        checkTarget = [   S[k-1][kk]
                                     ]
      elif k == len(S) -1 and kk == 0:
        checkTarget = [   S[k-1][kk], S[k-1][kk+1],
                                        S[k][kk+1]
                                                  ]
      elif k == len(S) -1 and kk> 0 and  kk < len(v)-1:
        checkTarget = [ S[k-1][kk-1],  S[k-1][kk], S[k-1][kk+1],
                        S[k][kk-1],                S[k][kk+1]
                                                                ]

      elif k == len(S) -1 and kk == len(v)-1:
        checkTarget = [ S[k-1][kk-1],  S[k-1][kk], 
                        S[k][kk-1]            
                                                               ]

      else:
        checkTarget = [ S[k-1][kk-1],  S[k-1][kk], S[k-1][kk+1],
                        S[k][kk-1],             S[k][kk+1],
                        S[k+1][kk-1], S[k+1][kk], S[k+1][kk+1]]

      print(len( [ i for i in checkTarget if i == "#"]  ), end="")
  print("", end="\n" if k != len(S)-1 else "" )

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())

s = [input() for i in range(h)]

def checkMine(c):
    if c == "#":
        return 1
    return 0


def dfs(x, y):
    nummines = 0
    if (s[y][x] != "#"):
        for i in range(-1, 2):
            for j in range(-1, 2):
                nx, ny = x + j, y + i
                if (0 <= nx and nx < w and 0 <= ny and ny < h):
                    nummines += checkMine(s[ny][nx])
    return nummines
for i in range(h):
    for j in range(w):
        nummines = dfs(j, i)
        if (nummines > 0):
            s[i] = s[i].replace(".", str(nummines), 1)

for string in s:
    print(string)

Submission status: Wrong Answer

Solution code:
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if (a[i][j]=="."):
            a[i][j] = 0
xx = [-1,-1,-1,0,0,1,1,1]
yy = [-1,0,1,-1,1,-1,0,1]
for i in range(h):
    for j in range(w):
        if (a[i][j] =="#"):
            continue
        for k in range(8):
            x = i+xx[k]
            y = j+yy[k]
            if (0<x and x<h and 0<y and y<w):
                if (a[x][y]=="#"):
                    a[i][j] += 1
for i in range(h):
    for j in range(w):
        if (a[i][j]!="#"):
            a[i][j] = str(a[i][j])
for i in range(h):
    print(''.join(a[i]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
mass = [input() for _ in range(H)]
for i in range(H):
    for j in range(W):
        if mass[i][j] == '.':
            count = 0
            try:
                if mass[i - 1][j - 1] == '#':
                    if j == 0:
                        pass
                    else:
                        count += 1
            except IndexError:
                pass
            try:
                if mass[i - 1][j] == '#':
                    count += 1
            except IndexError:
                pass
            try:
                if mass[i - 1][j + 1] == '#':
                    count += 1
            except IndexError:
                pass

            try:
                if mass[i][j - 1] == '#':
                    if j == 0:
                        pass
                    else:
                        count += 1
            except IndexError:
                pass
            try:
                if mass[i][j] == '#':
                    count += 1
            except IndexError:
                pass
            try:
                if mass[i][j + 1] == '#':
                    count += 1
            except IndexError:
                pass

            try:
                if mass[i + 1][j - 1] == '#':
                    if j == 0:
                        pass
                    else:
                        count += 1
            except IndexError:
                pass
            try:
                if mass[i + 1][j] == '#':
                    count += 1
            except IndexError:
                pass
            try:
                if mass[i + 1][j + 1] == '#':
                    count += 1
            except IndexError:
                pass
            print(count, end='')
        else:
            print('#', end='')
    print()

Submission status: Wrong Answer

Solution code:
import numpy as np

def dot_to_zero(letter):
    if letter == ".":
        return "0"
    else:
        return "#"

h, w = map(int, input().split(' '))

a = []
for i in range(h):
    s = np.array(list(map(dot_to_zero, input())))
    a.append(s)
a = np.vstack(a)

def add(array):
    for hei in [0,1,2]:
        for wid in [0,1,2]:
            if array[hei][wid] == "#":
                array[hei][wid] = "#"
            else:
                array[hei][wid] = str(int(array[hei][wid]) + 1)
    return array

a = np.pad(a, (1,1), 'edge')

print(a)

for index_h in range(1, h+1):
    for index_w in range(1, w+1):
        if a[index_h][index_w] == "#":
            print(index_h, index_w)
            a[index_h-1:index_h+2, index_w-1:index_w+2] = add(a[index_h-1:index_h+2, index_w-1:index_w+2])
            
a = a[1:-1, 1:-1]

for array in a:
    print("".join( array.tolist() ))

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(W):
        counter = 0
        if H_W_map[i][j] == '#':
            print('#', end='')
            continue

        if not j == 0:
            if H_W_map[i - 1][j - 1] == '#':
                counter += 1

        try:
            if H_W_map[i - 1][j] == '#':
                counter += 1
        except IndexError:
            pass

        try:
            if H_W_map[i - 1][j + 1] == '#':
                counter += 1
        except IndexError:
            pass

        if not j == 0:
            if H_W_map[i][j - 1] == '#':
                counter += 1

        try:
            if H_W_map[i][j + 1] == '#':
                counter += 1
        except IndexError:
            pass

        try:
            if not (j == 0):
                if H_W_map[i + 1][j - 1] == '#':
                    counter += 1
        except IndexError:
            pass

        try:
            if H_W_map[i + 1][j] == '#':
                counter += 1
        except IndexError:
            pass

        try:
            if H_W_map[i + 1][j + 1] == '#':
                counter += 1
        except IndexError:
            pass
        print(counter, end='')
    print()

Submission status: Wrong Answer

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

for i in range(H * W):
    search = [i-W-1, i-W, i-W+1, i-1, i+1, i+W-1, i+W, i+W+1]
    count = 0
    if S[i] == '#':
        continue
    for index in search:
        if index < 0 or index >= H * W:
            continue
        if S[index] == '#':
            count += 1
    S[i] = str(count)

for i in range(H):
    print("".join(S[i*W:(i+1)*W]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [[""]]*H
for i in range(H):
  S[i] = input()
print(S)

dh = [-1,-1,-1,0,0,1,1,1]
dw = [-1,0,1,-1,1,-1,0,1]

for i in range(H):
  for j in range(W):
    count=0
    if S[i][j]==".":
      for l in range(8):
        if H>i+dh[l]>-1 and W>j+dw[l]>-1:
          if S[i+dh[l]][j+dw[l]]=="#":
            count+=1
      S[i]=S[i][:j] + str(count) + S[i][j+1:]

for i in range(H):
  print(S[i])

Submission status: Wrong Answer

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

for i in range(h):
    for j in range(w):
        cnt = 0
        if A[i][j] == '.':
            for s in range(-1, 2):
                for t in range(-1, 2):
                    if i+s > 0 and i+s < h and j+t > 0 and j+t < w:
                        if A[i+s][j+t] == '#': cnt += 1
            A[i][j] = cnt
            print(cnt, end='')
        else:
            print('#', end='')
    print()

Submission status: Wrong Answer

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

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            cnt = 0
            for k in range(-1, 2):
                for l in range(-1, 2):
                    x = i + k
                    y = j + l
                    if 0 < x < H and 0 < y < W and S[x][y] == '#':
                        cnt += 1
            S[i][j] = cnt
            
for i in range(H):
    print(''.join(map(str, S[i])))

Submission status: Wrong Answer

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

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

for y in range(H):
  for x in range(W):
    if m[y][x] == '#':
      continue
    cnt = 0
    for dx, dy in dxy:
      if x+dx < 0 or y+dy < 0 or H <= y+dy or W <= x+dx:
        continue
      if m[y+dy][x+dx] == '#':
        cnt += 1
      m[y][x] = str(cnt)

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

Submission status: Wrong Answer

Solution code:
def main():
    H, W = map(int, input().split())
    board = [list(input()) for _ in range(H)]
    new_board = []
    for i in range(H):
        new_line = ""
        for j in range(W):
            num_bomb = 0
            if board[i][j] != "#":
                for k in range(-1, 2):
                    for l in range(-1, 2):
                        if not (k == 0 and l == 0):
                            try:
                                item = board[i+k][j+l]
                                if item == "#":
                                    num_bomb += 1 
                            except IndexError:
                                pass
                new_line += str(num_bomb)
            else:
                new_line += "#"

        new_board.append(new_line)

    for i in range(H):
        print(new_board[i])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

a = sys.stdin.readline().split(' ')
data = sys.stdin.readlines()

S = int(a[0])
H = int(a[1])

dx = [0,1,0,-1]
dy = [1,0,-1,0]

ans = 'Yes'
if S == 1 and H == 1:
    if data[0][0] == ".":
        ans = 'Yes'
    else:
        ans = 'No'
else:
    for i in range(S):
        for j in range(H):
            if data[i][j] == '.':
                continue
            else:
                for k in range(4):
                    x = j + dx[k]
                    y = i + dy[k]
                    if x < 0 or y < 0 or x >= H or y >= S:
                        continue
                    else:
                        if data[y][x] == "#":
                            ans = 'Yes'
                            break
                        else:
                            ans = 'No'
                            continue

print(ans)