[BOJ] 2448 별찍기 - 11

Time Lapse :NONE

2448.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
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>

using namespace std;

#define MAXSIZE 10000
char arr[MAXSIZE][MAXSIZE];
int N;

void answer_func(int k, int x, int y, int n)
{
if (k == 0)
{
arr[x][y] = '*';
arr[x + 1][y] = '*';
arr[x + 1][y + 2] = '*';
arr[x + 2][y] = '*';
arr[x + 2][y + 1] = '*';
arr[x + 2][y + 2] = '*';
arr[x + 2][y + 3] = '*';
arr[x + 2][y + 4] = '*';
return;
}

answer_func(k - 1, x, y, n / 2);
answer_func(k - 1, x + n / 2, y, n / 2);
answer_func(k - 1, x + n / 2, y + n, n / 2);
}

int main(void)
{
int k;
int t1, t2;
cin >> N;
for (int i = 0; i < MAXSIZE; i++)
{
for (int j = 0; j < MAXSIZE; j++)
{
arr[i][j] = ' ';
}
}
for (int i = 0; i <= 10; i++)
{
if (N / 3 == pow(2, i))
{
k = i;
break;
}
}

answer_func(k,0,0,N);

for (int i = 1; i <= N; i++)
{
for (int j = N - i; j > 0; j--)
{
cout << " ";
}

for (int j = 0; j < (i-1)*2+1; j++)
{
cout << arr[i - 1][j];
}

for (int j = N - i+1; j > 0; j--)
{
cout << " ";
}
cout << endl;
}
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/BOJ/2448/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.