ํฐ์คํ ๋ฆฌ ๋ทฐ
๐ฉ๐ป๐ป ๋ฌธ์
โ๐ป ํ์ด
๐จ 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
'dev > algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ / 11478๋ฒ / ์๋ก ๋ค๋ฅธ ๋ถ๋ถ ๋ฌธ์์ด์ ๊ฐ์ [Go][Python3] (0) | 2021.02.27 |
---|---|
BOJ / 1789๋ฒ / ์๋ค์ ํฉ [Go][Python3] (0) | 2021.02.26 |
BOJ / 20301๋ฒ / ๋ฐ์ ์์ธํธ์ค [Go][Python3] (0) | 2021.02.24 |
BOJ / 12789๋ฒ / ๋ํค๋ํค ๊ฐ์๋๋ฆฌ๋ฏธ [Go][Python3] (0) | 2021.02.23 |
BOJ / 6187๋ฒ / Going to the Movies [Go][Python3] (0) | 2021.02.22 |
๋๊ธ
๊ธ ๋ณด๊ดํจ
์ต๊ทผ์ ๋ฌ๋ฆฐ ๋๊ธ
TAG
- ๋งฅ๋ถ
- BFS
- ์๊ณ ๋ฆฌ์ฆ
- ๋ถํ ์ ๋ณต
- dp
- ํ๋ก์ด๋์์ฌ
- baekjoon
- ํ
- ballet
- ์คํ
- go
- ๋ฐ๋
- MongoDB
- BOJ
- ์๊ฐ๊ต์ฒด
- ์๋ฐ
- AWS
- dfs
- ๋งฅ๋ถํ๋ก
- Algorithm
- java
- ๋ธ๋ฃจํธํฌ์ค
- ๋ชฝ๊ณ ๋๋น
- Golang
- Macbook pro 2012 mid 13
- ๋งฅ๋ถ ์ ๊ทธ๋ ์ด๋
- python3
- ์ด๋ถํ์
- ๋ฐฑ์ค
- ํด์๋งต
- Total
- Today
- Yesterday