풀이: 파이썬
def matrix_print(matrix):
for i in matrix:
for j in i:
print(j,end=" ")
print()
def check(x,y,n):
return (x<n and y<n and x>=0 and y>=0)
n = int(input())
matrix = []
for _ in range(n):
matrix.append([' ' for _ in range(n)])
#R - D - L - U
x,y = 0, 0
xs = [0,1,0,-1]
ys = [1,0,-1,0]
goto = 0
for _ in range(n):
while check(x+xs[goto],y+ys[goto],n):
if check(x+(xs[goto]*2),y+(ys[goto]*2),n) and matrix[x+(xs[goto]*2)][y+(ys[goto]*2)] == "#":
matrix[x][y] = "#"
break
matrix[x][y] = "#"
x += xs[goto]
y += ys[goto]
goto = (goto+1) %4
matrix_print(matrix)
오래 걸렸다 ..
'Code IT > Algorithm' 카테고리의 다른 글
[프로그래머스] 기능개발 (Python) (0) | 2022.03.13 |
---|---|
[프로그래머스] 위장 (Python) (0) | 2022.03.13 |
[구름에듀] 놀이공원 (Python) (0) | 2022.03.11 |
[프로그래머스] 가장 큰 수 - Sort (Java) (0) | 2021.11.04 |
[프로그래머스] 더 맵게 - Heap (Java) (0) | 2021.08.28 |
댓글