ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

๐Ÿ‘ฉ๐Ÿป‍๐Ÿ’ป ๋ฌธ์ œ

 

10994๋ฒˆ: ๋ณ„ ์ฐ๊ธฐ - 19

์˜ˆ์ œ๋ฅผ ๋ณด๊ณ  ๊ทœ์น™์„ ์œ ์ถ”ํ•œ ๋’ค์— ๋ณ„์„ ์ฐ์–ด ๋ณด์„ธ์š”.

www.acmicpc.net


โœ๐Ÿป ํ’€์ด

๐ŸŽจ Go

// https://www.acmicpc.net/problem/10994
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

var (
	stars [][]string
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanln(reader, &n)

	stars = make([][]string, 4*n-3)
	for i := 0; i < len(stars); i++ {
		stars[i] = make([]string, 4*n-3)
		for j := 0; j < len(stars[i]); j++ {
			stars[i][j] = " "
		}
	}

	drawStar(n, 0, 0)

	for i := 0; i < len(stars); i++ {
		fmt.Fprintln(writer, strings.Join(stars[i], ""))
	}
}

func drawStar(n, row, col int) {
	length := 4*n - 3 // ๋ณ„์„ ๊ทธ๋ฆด ์‚ฌ๊ฐํ˜•์˜ ๋ณ€์˜ ๊ธธ์ด
	if length == 1 {
		stars[row][col] = "*"
		return
	}

	for r := row; r < row+length; r++ { // ์„ธ๋กœ๋ณ€ ๊ทธ๋ฆฌ๊ธฐ
		stars[r][col] = "*"
		stars[r][col+length-1] = "*"
	}

	for c := col + 1; c < col+length-1; c++ { // ๊ฐ€๋กœ๋ณ€ ๊ทธ๋ฆฌ๊ธฐ
		stars[row][c] = "*"
		stars[row+length-1][c] = "*"
	}

	drawStar(n-1, row+2, col+2) // ๋‚ด๋ถ€์˜ ์‚ฌ๊ฐํ˜• ๋ณ„ ๊ทธ๋ฆฌ๊ธฐ
}

๐ŸŽจ Python3

# https://www.acmicpc.net/problem/10994
import sys

stars = []

def draw_star(n, row, col):
    length = 4*n - 3
    if length == 1:
        stars[row][col] = "*"
        return
    for r in range(row, row+length):
        stars[r][col] = "*"
        stars[r][col+length-1] = "*"
    for c in range(col+1, col+length-1):
        stars[row][c] = "*"
        stars[row+length-1][c] = "*"
    draw_star(n-1, row+2, col+2)

if __name__ == "__main__":
    n = int(sys.stdin.readline())
    stars = [[" " for i in range(4*n-3)] for j in range(4*n-3)]
    draw_star(n, 0, 0)
    for i in stars:
        print("".join(i))
728x90
๋Œ“๊ธ€