https://www.acmicpc.net/problem/16956
R, C = map(int, input().split())
MAP = [list(input()) for _ in range(R)]
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1]
ck = False
for i in range(R):
for j in range(C):
if MAP[i][j] == 'W':
for k in range(4):
ii, jj = i + dx[k], j + dy[k]
if ii < 0 or ii == R or jj <0 or jj == C:
continue
if MAP[ii][jj] =='S':
ck = True
if ck:
print(0)
else:
print(1)
for i in range(R):
for j in range(C):
if MAP[i][j] not in 'SW':
MAP[i][j] = 'D'
for i in MAP:
print(''.join(i))
'알고리즘 > 백준 (Pyhthon)' 카테고리의 다른 글
[알고리즘] 백준 12100 2048(Easy) / python, dfs (1) | 2020.03.16 |
---|---|
[알고리즘] 백준 14620 꽃길 / python (0) | 2020.03.14 |
[알고리즘] 백준 2484 주사위 네개 / python (0) | 2020.03.13 |
[알고리즘] 백준 2480 주사위 세개 / python (0) | 2020.03.13 |
[알고리즘] 백준 9037 The candy war / python (0) | 2020.03.13 |