BOJ - 10997 - 별 찍기 - 22

Updated:

def recursive(n, index, Star):
    if n == 1:
        Star[index][index] = '*'
        Star[index + 1][index] = '*'
        Star[index + 2][index] = '*'
        return

    row = 4 * (n - 1) + 1
    col = 4 * (n - 1) + 3

    for r in range(index, row + index):
        for c in range(index, col + index):
            if r == index or c == index or r == row + index - 1 or c == col + index - 1:
                Star[c][r] = '*'

    Star[index + 1][index + row - 1] = ' '
    Star[index + 2][index + row - 2] = '*'

    recursive(n - 1, index + 2, Star)
    return

def solution():
    N = int(input())
    if N == 1:
        print("*")
        return

    row = 4 * (N - 1) + 1
    col = 4 * (N - 1) + 3

    Star = [[' '] * row for _ in range(col)]

    recursive(N, 0, Star)
    for i in range(col):
        if i == 1:
            print('*')
            continue
        for j in range(row):
            print(Star[i][j], end="")
        print("")

solution()

https://www.acmicpc.net/problem/10997

Categories:

Updated:

Leave a comment