Skip to content

Commit d8e699b

Browse files
committed
[Gold V] Title: 별 찍기 - 10, Time: 372 ms, Memory: 162976 KB -BaekjoonHub
1 parent 9757210 commit d8e699b

2 files changed

Lines changed: 33 additions & 23 deletions

File tree

백준/Gold/2447. 별 찍기 - 10/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 76980 KB, 시간: 416 ms
7+
메모리: 162976 KB, 시간: 372 ms
88

99
### 분류
1010

1111
분할 정복, 재귀
1212

1313
### 제출 일자
1414

15-
2024년 5월 22일 03:05:44
15+
2025년 6월 26일 20:05:48
1616

1717
### 문제 설명
1818

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,33 @@
1-
struct Fractal{
2-
var length: Int?
3-
var answer = ""
4-
mutating func addLF(){ answer += "\n" }
5-
mutating func drawFractal(x: Int, y: Int, length: Int){
6-
if length == 1 { answer += "*" }
7-
else if (x / (length/3)) % 3 == 1 && (y / (length/3)) % 3 == 1 {
8-
answer += " "
9-
}
10-
else{
11-
drawFractal(x: x, y: y, length: length/3)
12-
}
1+
let n = Int(readLine()!)!
2+
var fractal = [[String]](repeating: [String](repeating: " ", count: n), count: n)
3+
4+
func draw(fromRow: Int, fromCol: Int, size: Int) {
5+
if size == 3 {
6+
fractal[fromRow][fromCol] = "*"
7+
fractal[fromRow][fromCol+1] = "*"
8+
fractal[fromRow][fromCol+2] = "*"
9+
10+
fractal[fromRow+1][fromCol] = "*"
11+
fractal[fromRow+1][fromCol+2] = "*"
12+
13+
fractal[fromRow+2][fromCol] = "*"
14+
fractal[fromRow+2][fromCol+1] = "*"
15+
fractal[fromRow+2][fromCol+2] = "*"
16+
return
1317
}
18+
draw(fromRow: fromRow, fromCol: fromCol, size: size/3)
19+
draw(fromRow: fromRow, fromCol: fromCol + size/3, size: size/3)
20+
draw(fromRow: fromRow, fromCol: fromCol + size/3 + size/3, size: size/3)
21+
22+
draw(fromRow: fromRow + size/3, fromCol: fromCol, size: size/3)
23+
draw(fromRow: fromRow + size/3, fromCol: fromCol + size/3 + size/3, size: size/3)
24+
25+
draw(fromRow: fromRow + size/3 + size/3, fromCol: fromCol, size: size/3)
26+
draw(fromRow: fromRow + size/3 + size/3, fromCol: fromCol + size/3, size: size/3)
27+
draw(fromRow: fromRow + size/3 + size/3, fromCol: fromCol + size/3 + size/3, size: size/3)
1428
}
15-
let length = Int(readLine()!)!
16-
var fractal = Fractal(length: length)
17-
for i in 0..<length{
18-
for j in 0..<length{
19-
fractal.drawFractal(x: i, y: j, length: length)
20-
}
21-
fractal.addLF()
22-
}
23-
print(fractal.answer)
29+
30+
draw(fromRow: 0, fromCol: 0, size: n)
31+
let result = fractal.map { $0.reduce(into: "") { $0.write($1) } }.joined(separator: "\n")
32+
33+
print(result)

0 commit comments

Comments
 (0)