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=[]
cnt=0
for i in range(h):
    s.append(list(input()))
if h==1 and w==1:
    if s[0][0]=='#':
        print('#')
    else:
        print(0)
elif h==1:
    for i in range(w):
        if s[0][i]=='#':
            continue
        if i==0:
            if s[0][i+1]=='#':
                s[0][i]=='1'
            else:
                s[0][i]=='0'
        elif i==w-1:
            if s[0][i-1]=='#':
                s[0][i]=='1'
            else:
                s[0][i]=='0'
        else:
            if s[0][i+1]=='#':
                cnt+=1
            if s[0][i-1]=='#':
                cnt+=1
            s[0][i]=str(cnt)
            cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''
elif w==1:
    for i in range(h):
        if s[i][0]=='#':
            continue
        if i==0:
            if s[i+1][0]=='#':
                s[i][0]=='1'
            else:
                s[i][0]=='0'
        elif i==h-1:
            if s[i-1][0]=='#':
                s[i][0]=='1'
            else:
                s[i][0]=='0'
        else:
            if s[i+1][0]=='#':
                cnt+=1
            if s[i-1][0]=='#':
                cnt+=1
            s[i][0]=str(cnt)
            cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''
else:
    for j in range(h):
        for k in range(w):
            if j==0:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
            elif j==h-1:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0 
            elif 0<j<h-1:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[]
cnt=0
for i in range(h):
    s.append(list(input()))
if h==1 and w==1:
    if s[0][0]=='#':
        print('#')
    else:
        print(0)
elif h==1:
    for i in range(w):
        if i==0:
            if s[0][i+1]=='#':
                s[0][i]=='1'
            else:
                s[0][i]=='0'
        elif i==w-1:
            if s[0][i-1]=='#':
                s[0][i]=='1'
            else:
                s[0][i]=='0'
        else:
            if s[0][i+1]=='#':
                cnt+=1
            if s[0][i-1]=='#':
                cnt+=1
            s[0][i]=str(cnt)
            cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''
elif w==1:
    for i in range(h):
        if i==0:
            if s[i+1][0]=='#':
                s[i][0]=='1'
            else:
                s[i][0]=='0'
        elif i==h-1:
            if s[i-1][0]=='#':
                s[i][0]=='1'
            else:
                s[i][0]=='0'
        else:
            if s[i+1][0]=='#':
                cnt+=1
            if s[i-1][0]=='#':
                cnt+=1
            s[i][0]=str(cnt)
            cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''
else:
    for j in range(h):
        for k in range(w):
            if j==0:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
            elif j==h-1:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0 
            elif 0<j<h-1:
                if s[j][k]=='#':
                    continue
                else:
                    if k==0:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    elif k==w-1:
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
                    else:
                        if s[j][k+1]=='#':
                            cnt+=1
                        if s[j-1][k]=='#':
                            cnt+=1
                        if s[j-1][k+1]=='#':
                            cnt+=1
                        if s[j-1][k-1]=='#':
                            cnt+=1
                        if s[j+1][k]=='#':
                            cnt+=1
                        if s[j+1][k+1]=='#':
                            cnt+=1
                        if s[j][k-1]=='#':
                            cnt+=1
                        if s[j+1][k-1]=='#':
                            cnt+=1
                        s[j][k]=str(cnt)
                        cnt=0
    ans=''
    for l in range(h):
        for b in range(w):
            ans+=s[l][b]
        print(ans)
        ans=''

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
S = [list(input()) for i in range(H)]
S=[[0 if j == "." else "#" for j in i] for i in S]

for i in range(H):
          for j in range(W):
            if S[i][j]=='#':

                try:S[i-1][j-1]
                except IndexError:pass
                else:
                    if  i-1>=0 and j-1>0 and S[i-1][j-1]!='#':
                        S[i-1][j-1]+=1

                try:S[i-1][j]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j]!='#':
                        S[i-1][j]+=1

                try:S[i-1][j+1]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j+1]!='#':
                        S[i-1][j+1]+=1

                try:S[i][j-1]
                except IndexError:pass
                else:
                    if  j-1>=0 and S[i][j-1]!='#':
                        S[i][j-1]+=1
                        
                try:S[i][j+1]
                except IndexError:pass
                else:
                    if  S[i][j+1]!='#':
                        S[i][j+1]+=1

                try:S[i+1][j-1]
                except IndexError:pass
                else:
                    if j-1>=0 and S[i+1][j-1]!='#':
                        S[i+1][j-1]+=1

                try:S[i+1][j]
                except IndexError:pass
                else:
                    if S[i+1][j]!='#':
                        S[i+1][j]+=1

                try:S[i+1][j+1]
                except IndexError:pass
                else:
                    if S[i+1][j+1]!='#':
                        S[i+1][j+1]+=1
for i in S:
    print(*i,sep="")

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
S = [list(input()) for i in range(H)]
S=[[0 if j == "." else "#" for j in i] for i in S]

for i in range(H):
          for j in range(W):
            if S[i][j]=='#':

                try:S[i-1][j-1]
                except IndexError:pass
                else:
                    if  i-1>=0 and j-1>0 and S[i-1][j-1]!='#':
                        S[i-1][j-1]+=1

                try:S[i-1][j]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j]!='#':
                        S[i-1][j]+=1

                try:S[i-1][j+1]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j+1]!='#':
                        S[i-1][j+1]+=1

                try:S[i][j-1]
                except IndexError:pass
                else:
                    if  j-1>=0 and S[i][j-1]!='#':
                        S[i][j-1]+=1
                        
                try:S[i][j+1]
                except IndexError:pass
                else:
                    if  S[i][j+1]!='#':
                        S[i][j+1]+=1

                try:S[i+1][j-1]
                except IndexError:pass
                else:
                    if j-1>=0 and S[i+1][j-1]!='#':
                        S[i+1][j-1]+=1

                try:S[i+1][j]
                except IndexError:pass
                else:
                    if S[i+1][j]!='#':
                        S[i+1][j]+=1

                try:S[i+1][j+1]
                except IndexError:pass
                else:
                    if S[i+1][j+1]!='#':
                        S[i+1][j+1]+=1
for i in S:
    print(*i)

Submission status: Wrong Answer

Solution code:
H,W = map(int, input().split())
S = [list(input()) for i in range(H)]
S=[[0 if j == "." else "#" for j in i] for i in S]

for i in range(H):
          for j in range(W):
            if S[i][j]=='#':

                try:S[i-1][j-1]
                except IndexError:pass
                else:
                    if  i-1>=0 and j-1>0 and S[i-1][j-1]!='#':
                        S[i-1][j-1]+=1

                try:S[i-1][j]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j]!='#':
                        S[i-1][j]+=1

                try:S[i-1][j+1]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j+1]!='#':
                        S[i-1][j+1]+=1

                try:S[i][j-1]
                except IndexError:pass
                else:
                    if  j-1>=0 and S[i][j-1]!='#':
                        S[i][j-1]+=1
                        
                try:S[i][j+1]
                except IndexError:pass
                else:
                    if  S[i][j+1]!='#':
                        S[i][j+1]+=1

                try:S[i+1][j-1]
                except IndexError:pass
                else:
                    if j-1>=0 and S[i+1][j-1]!='#':
                        S[i+1][j-1]+=1

                try:S[i+1][j]
                except IndexError:pass
                else:
                    if S[i+1][j]!='#':
                        S[i+1][j]+=1

                try:S[i+1][j+1]
                except IndexError:pass
                else:
                    if S[i+1][j+1]!='#':
                        S[i+1][j+1]+=1
print(S)

Submission status: Wrong Answer

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

def count_mine(i, j):
    if S[i][j] == "#":
        return "#"
    else:
        if H == 1 and W == 1:
            return 0
        elif H == 1:
            if j == 0:
                if S[0][1] == "#":
                    return 1
                else:
                    return 0
            elif j == W - 1:
                if S[0][W - 2] == "#":
                    return 1
                else:
                    return 0
            else:
                return [S[0][j - 1], S[0][j + 1]].count("#")
        elif W == 1:
            if i == 0:
                if S[1][0] == "#":
                    return 1
                else:
                    return 0
            elif i == H - 1:
                if S[H - 2][0] == "#":
                    return 1
                else:
                    return 0
            else:
                return [S[i - 1][0], S[i + 1][0]].count("#")
        else:
            if i == 0 and j == 0:
                return [S[0][1], S[1][0], S[1][1]].count("#")
            elif i == 0 and j == W - 1:
                return [S[0][j - 1], S[1][j - 1], S[1][j]].count("#")
            elif i == H - 1 and j == 0:
                return [S[i - 1][j], S[i - 1][j + 1], S[i][j + 1]].count("#")
            elif i == H - 1 and j == W - 1:
                return [S[i - 1][j], S[i - 1][j - 1], S[i][j - 1]].count("#")
            elif i == 0:
                return [S[0][j - 1], S[0][j + 1], S[1][j - 1], S[1][j], S[1][j + 1]].count("#")
            elif i == H - 1:
                return [S[i][j - 1], S[i][j + 1], S[i - 1][j - 1], S[i - 1][j], S[i - 1][j + 1]].count("#")
            elif j == 0:
                return [S[i - 1][0], S[i + 1][0], S[i - 1][1], S[i][1], S[i + 1][1]].count("#")
            elif j == W - 1:
                return [S[i - 1][j], S[i + 1][j], S[i - 1][j - 1], S[i][j - 1], S[i + 1][j - 1]].count("#")
            else:
                return [S[i - 1][j - 1], S[i - 1][j], S[i - 1][j], S[i][j - 1], S[i][j + 1], S[i + 1][j - 1], S[i + 1][j], S[i + 1][j + 1]].count("#")

for i, row in enumerate(S):
    for j, sign in enumerate(row):
        print(count_mine(i, j), end="")
    print()

Submission status: Wrong Answer

Solution code:
dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]
h,w=map(int,input().split())
field = []
for i in range(h):
    field.append(list(input()))
for y in range(h):
    for x in range(w):
        if field[y][x]=="#":
            continue
        cnt=0
        for k in range(8):
            nx=x+dx[k]
            ny=y+dy[k]
            if nx<0 or nx>=w or ny<0 or ny>=h:
                continue
            if field[ny][nx]=="#":
                cnt+=1
            field[y][x]=str(cnt)
for i in range(h):
    print("".join(field[i]))

Submission status: Wrong Answer

Solution code:
dx=[-1,0,1,-1,1,-1,0,1]
dy=[-1,-1,-1,0,0,1,1,1]
h,w=map(int,input().split())
field = []
for i in range(h):
    field.append(list(input()))
print(field)

for y in range(h):
    for x in range(w):
        if field[y][x]=="#":
            continue
        cnt=0
        for k in range(8):
            nx=x+dx[k]
            ny=y+dy[k]
            if nx<0 or nx>=w or ny<0 or ny>=h:
                continue
            if field[ny][nx]=="#":
                cnt+=1
            field[y][x]=str(cnt)
for i in range(h):
    print("".join(field[i]))

Submission status: Wrong Answer

Solution code:
#import sys

#if sys.platform =='ios':
#	sys.stdin=open('input.txt')

h, w = [int(x) for x in input().split()]
board = [input() for _ in range(h)]

mines=['' for _ in range(h)]

print(board)

for row in range(h):
	for col in range(w):
		if board[row][col] != '#':
			counts = 0
			dx = [x for x in range(-1, 2) if (col+x>=0 and col+x<w)]
			dy = [y for y in range(-1, 2) if (row+y>=0 and row+y<h)]
			#print('row:{}, col:{}, dx:{}, dy:{}'.format(row,col,dx,dy))
			for x in dx:
				for y in dy:
					#print('row+y:{}, col+x:{}'.format(row+y, col+x))
					if board[row+y][col+x] == '#':
						counts += 1
			mines[row] += str(counts)
		else:
			mines[row] += '#'
for mine in mines:
	print(mine)

Submission status: Wrong Answer

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('input.txt')

h, w = [int(x) for x in input().split()]
board = [input() for _ in range(h)]

mines=['' for _ in range(h)]

print(board)

for row in range(h):
	for col in range(w):
		if board[row][col] != '#':
			counts = 0
			dx = [x for x in range(-1, 2) if (col+x>=0 and col+x<w)]
			dy = [y for y in range(-1, 2) if (row+y>=0 and row+y<h)]
			#print('row:{}, col:{}, dx:{}, dy:{}'.format(row,col,dx,dy))
			for x in dx:
				for y in dy:
					#print('row+y:{}, col+x:{}'.format(row+y, col+x))
					if board[row+y][col+x] == '#':
						counts += 1
			mines[row] += str(counts)
		else:
			mines[row] += '#'
for mine in mines:
	print(mine)

Submission status: Wrong Answer

Solution code:
h,w=[int(i) for i in input().split()]
s=[input() for i in range(h)]
ans=""
for i in range(h):
    for j in range(w):
        cnt=0
        if s[i][j]=="#":
            ans+="#"
        else:
            for x,y in [(i+1,j-1),(i+1,j),(i+1,j+1),(i-1,j-1),(i-1,j),(i-1,j+1),(i,j+1),(i,j-1)]:
                try:
                    if s[x][y]=="#":
                        cnt+=1
                except:
                    pass
            ans+=str(cnt)
    ans+="\n"
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
Slist = [["."] * (W + 2), ]
for _ in range(H):
    line = list(input())
    line.insert(0, ".")
    line.append(".")
    Slist.append(line)
Slist.append(["."] * (W + 2))
# print(Slist)
point_tuple = ((-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):
        print(Slist[i][j], i, j)
        if Slist[i][j] == ".":
            counter = 0
            for a, b in point_tuple:
                if Slist[i - a][j - b] == "#":
                    counter += 1
            Slist[i][j] = str(counter)

for i in range(1, H + 1):
    print("".join(Slist[i][1:-1]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
Slist = [["."] * (W + 2), ]
for _ in range(H):
    line = list(input())
    line.insert(0, ".")
    line.append(".")
    Slist.append(line)
Slist.append(["."] * (W + 2))
# print(Slist)
point_tuple = ((-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):
        # print(Slist[i][j], i, j)
        if Slist[i][j] == ".":
            counter = 0
            for a, b in point_tuple:
                if Slist[i - a][j - b] == "#":
                    counter += 1
            Slist[i][j] = str(counter)

for i in range(1, H + 1):
    print("".join(Slist[i][1:-1]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
Slist = [["."] * (W + 2), ]
for _ in range(H):
    line = list(input())
    line.insert(0, ".")
    line.insert(-1, ".")
    Slist.append(line)
Slist.append(["."] * (W + 2))

point_tuple = ((-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 Slist[i][j] == ".":
            counter = 0
            for a, b in point_tuple:
                if Slist[i - a][j - b] == "#":
                    counter += 1
            Slist[i][j] = str(counter)

for i in range(1, H + 1):
    print("".join(Slist[i][1:-1]))

Submission status: Wrong Answer

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

def check_bomb(i,j):
    try:
        if H_lis[i][j]==".":
            return 0
        elif H_lis[i][j]=="#":
            return 1
        else:
            return 0
    except:
        return 0

for i in range(H):
    ans = ""
    for j in range(W):
        if check_bomb(i,j)==1:
            ans += "#"
        else:
            ans+=str(check_bomb(i-1,j-1)+check_bomb(i-1,j)+check_bomb(i-1,j+1)+check_bomb(i,j-1)+check_bomb(i,j+1)+check_bomb(i+1,j-1)+check_bomb(i+1,j)+check_bomb(i+1,j+1))
    print(ans)

Submission status: Wrong Answer

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

S=[input() for _ in range(H)]

ans =[]

for i in range(H):
    s = ''
    for j in range(W):
        if S[i][j] != '#':
            cnt = 0
            for k in range(-1, 2):
                for m in range(-1, 2):
                    col = i + k
                    row = j + m
                    if (col < 0 or row < 0 or col >= H-1 or row >= W-1) or (k == 0 and m == 0):
                        continue
                    else:
                        if S[col][row] == '#':
                            cnt += 1
            s += str(cnt)
        else:
            s += '#'
    ans.append(s)

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

Submission status: Wrong Answer

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


def get_or_period(l, passed_x, passed_y):
    if passed_x in [-1, w]:
        return '.'
    if passed_y in [-1, h]:
        return '.'
    return l[passed_y][passed_x]


convertedMatrix = []

for y, row in enumerate(matrix):
    convertedMatrix.append([])
    for x, cell in enumerate(row):
        convertedCell = 0
        if matrix[y][x] == "#":
            convertedCell = "#"
            convertedMatrix[y].append(convertedCell)
            continue
        if x == 0 and y == 3:
            print("a")
        for exam_x in [-1, 0, 1]:
            for exam_y in [-1, 0, 1]:
                if get_or_period(matrix, x + exam_x, y + exam_y) == "#":
                    convertedCell += 1
        convertedMatrix[y].append(convertedCell)

for row in convertedMatrix:
    print("".join(map(str, row)))

Submission status: Wrong Answer

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


def get_or_period(l, passed_x, passed_y):
    try:
        return l[passed_y][passed_x]
    except IndexError:
        return '.'


convertedMatrix = []

for y, row in enumerate(matrix):
    convertedMatrix.append([])
    for x, cell in enumerate(row):
        convertedCell = 0
        if matrix[y][x] == "#":
            convertedCell = "#"
            convertedMatrix[y].append(convertedCell)
            continue
        for exam_x in [-1, 0, 1]:
            for exam_y in [-1, 0, 1]:
                if get_or_period(matrix, x + exam_x, y + exam_y) == "#":
                    convertedCell += 1
        convertedMatrix[y].append(convertedCell)

for row in convertedMatrix:
    print("".join(map(str, row)))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(H)]
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            cnt = 0
            for k in range(8):
                if(i+dy[k] >= 0 and i+dy[k] < H and j+dx[k]>0 and j+dx[k] < W and S[i+dy[k]][j+dx[k]]=='#'):
                    cnt+=1
            print(cnt, end='')
        else:
            print(S[i][j], end='')
    print('')

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for i in range(h)]
for i in range(h):
    l = ' '
    for j in range(w):
        if s[i][j] == '#':
            l = '#'
        else:
            total = 0
            for x in range(max(0, i-1), min(h, i+1)):
                for y in range(max(0, j-1), min(h, j+1)):
                    total += s[x][y].count("#")
                l = str(total)
        print(l,end = '')
    print('')

Submission status: Wrong Answer

Solution code:
# -*- coding:utf-8 -*-

#下、右、上、左、右下、右上、左下、左上
dy=[1,0,-1,0,1,-1,1,-1]
dx=[0,1,0,-1,1,1,-1,-1]

H,W=map(int,input().split())
field=[]

for i in range(H):
  field.append(list(input()))

for j in range(H):
  for k in range(W):
    if field[j][k]=='#':
      continue
      
      cnt=0
      
      for n in range(8):
        x=j+dx[n]
        y=k+dy[n]
        
        if y<0 or H<=y or x<0 or W<=x:
          continue
        
        if field[y][x]=='#':
          cnt+=1
      
      field[j][k]=str(cnt)

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