반응형
https://www.acmicpc.net/problem/10993
n = int(input())
def star(depth):
if depth == 1:
return ['*']
m = 2**(depth+1)-3
table = [[' ' for _ in range(m)] for _ in range(m)]
k = 2**depth-3
shift = 2**(depth-1)
if depth % 2 == 0:
for i in range(m):
table[0][i] = '*'
j = 0
for i in range(0, m, 2):
table[i][j] = '*'
j += 1
j -= 1
for i in range(-1, -m, -2):
table[i][j] = '*'
j += 1
a = star(depth - 1)
for i in range(k):
for j in range(k):
table[2+i][j+shift] = a[i][j]
else:
for i in range(m):
table[-1][i] = '*'
j = 0
for i in range(-1, -m, -2):
table[i][j] = '*'
j += 1
for i in range(0, m, 2):
table[i][j] = '*'
j += 1
a = star(depth - 1)
for i in range(k):
for j in range(k):
table[i+k+1][j+shift] = a[i][j]
return table
result = star(n)
for i in range(2**(n+1)-3):
a = "".join(result[i]).rstrip()
if a:
print(a)
재귀 연습!
댓글