-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2448.cpp
More file actions
64 lines (57 loc) · 1.28 KB
/
2448.cpp
File metadata and controls
64 lines (57 loc) · 1.28 KB
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
// 2448. 별 찍기 - 11
// 2020.06.19
// 별 찍기
#include<iostream>
using namespace std;
char arr[3072][6144];
// 삼각형 그리는 함수(시에르핀스키 가스켓)
// n은 삼각형의 높이, 삼각형의 위 꼭지점 좌표(x,y)
void printStar(int n, int x, int y)
{
// n=3일때 기본적인 삼각형 그리기
if (n == 3)
{
arr[y][x] = '*';
arr[y + 1][x - 1] = '*';
arr[y + 1][x + 1] = '*';
arr[y + 2][x - 2] = '*';
arr[y + 2][x - 1] = '*';
arr[y + 2][x] = '*';
arr[y + 2][x + 1] = '*';
arr[y + 2][x + 2] = '*';
return;
}
printStar(n / 2, x, y); // 위
printStar(n / 2, x - (n / 2), y + (n / 2)); // 좌
printStar(n / 2, x + (n / 2), y + (n / 2)); // 우
}
int main()
{
int n;
cin >> n;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2 * n; j++)
{
if (j == 2 * n - 1)
{
arr[i][j] = NULL;
}
else
{
arr[i][j] = ' ';
}
}
}
// 출력
printStar(n, n - 1, 0);
for (int i = 0; i < n; i++)
{
for (int j = 0; j < 2 * n - 1; j++)
{
cout << arr[i][j];
}
cout << endl;
}
return 0;
}