[BOJ] 2447 별찍기 - 10

Time Lapse :NONE

2447.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

char arr[2187][2187];
int N;
void print()
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
cout << arr[i][j];
}
cout << endl;
}
}

void draw(int x, int y,int length, bool tf)
{
if (length == 1 && tf)
{
arr[x + 1][y + 1] = ' ';
return;
}
if (length == 1 && !tf)
{
for (int i = x; i < x+3; i++)
{
for (int j = y; j < y+3; j++)
{
arr[i][j] = ' ';
}
}
return;
}

draw(x, y, length - 1, tf);
draw(x + pow(3, length - 1), y, length - 1, tf);
draw(x + (pow(3, length - 1) * 2), y, length - 1, tf);

draw(x, y +pow(3, length - 1), length - 1, tf);
draw(x + pow(3, length - 1), y + pow(3, length - 1), length - 1, false);
draw(x + (pow(3, length - 1) * 2), y + pow(3, length - 1), length - 1, tf);

draw(x, y + (pow(3, length - 1) * 2), length - 1, tf);
draw(x + pow(3, length - 1), y + (pow(3, length - 1) * 2), length - 1, tf);
draw(x + (pow(3, length - 1) * 2), y + (pow(3, length - 1) * 2), length - 1, tf);

}

int main(void)
{
cin >> N;
int num=3;
for (int i = 0; i < 8; i++)
{
if (num == N)
{
num = i+1;
break;
}
num = num * 3;
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
{
arr[i][j] = '*';
}
}
draw(0, 0, num, true);
print();
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2447/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.