-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrawer.cpp
More file actions
59 lines (55 loc) · 1.58 KB
/
drawer.cpp
File metadata and controls
59 lines (55 loc) · 1.58 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
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <math.h>
using namespace std;
void draw(bool **array, int n, int row, int col) {
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
array[row-i][col-j] = true;
array[row-i][col+j] = true;
}
array[row-i][col+n] = true;
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
array[row+i][col+j] = true;
array[row+i][col-j+1] = true;
}
}
}
void calculateDraw(bool **array, int n, int row, int col) {
draw(array, n>>1, row, col);
if (n > 2) {
calculateDraw(array, n>>1, row-(n>>1), col-(n>>1));
calculateDraw(array, n>>1, row+(n>>1), col-(n>>1));
calculateDraw(array, n>>1, row+(n>>1), col+(n>>1));
calculateDraw(array, n>>1, row-(n>>1), col+(n>>1));
}
}
int main() {
int n;
scanf("%d",&n);
int arraySize = 0;
for (int i = 0; i < log2(n); ++i) {
arraySize += pow(2, i);
}
arraySize *= 2;
arraySize += n;
bool **array = (bool **)calloc(sizeof(bool*),arraySize+1);
for (int i = 0; i <= arraySize; ++i) {
array[i] = (bool *)calloc(sizeof(bool), arraySize+1);
}
//draw(array, n>>1, arraySize>>1, arraySize>>1);
calculateDraw(array, n, arraySize>>1, arraySize>>1);
for (int i = 0; i <= arraySize; ++i) {
for (int j = 0; j <= arraySize; ++j) {
if (array[i][j]) {
printf("X");
}
else printf(" ");
}
printf("\n");
}
//printf("%d",arraySize);
}