-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2448.cpp
115 lines (99 loc) · 2.24 KB
/
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//
// Created by 융미 on 2019-04-28.
//2448 별 찍기 - 11
#include <iostream>
char arr[3072][6144];
void star(int h, int x, int y) //입력은 삼각형의 높이, x, y좌표
{
//base case : 삼각형 높이가 3인 경우 삼각형 찍고 탈출
if(h==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;
}
//위 삼각형
star(h/2, x, y);
//왼쪽 삼각형
star(h/2, x-(h/2), y+(h/2));
//오른쪽 삼각형
star(h/2, x+(h/2), y+(h/2));
}
int main(){
int input = 0;
std::cin>>input;
//배열 공백 초기화
for(int i = 0; i<input; i++)
{
for(int j = 0; j < input*2 -1; j++){
arr[i][j] = ' ';
}
}
star(input, input-1, 0);
for(int i = 0; i<input; i++)
{
for(int j = 0; j < input*2 -1; j++){
std::cout << arr[i][j];
}
std::cout << '\n';
}
return 0;
}
////*2448 재귀 별찍기-C출력 버전
//#include <cstdio>
//
//char arr[3072][6144];
//
//void star(int h, int x, int y) //입력은 삼각형의 높이, x, y좌표
//{
// //base case : 삼각형 높이가 3인 경우 삼각형 찍고 탈출
// if(h==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;
// }
//
// //위 삼각형
// star(h/2, x, y);
// //왼쪽 삼각형
// star(h/2, x-(h/2), y+(h/2));
// //오른쪽 삼각형
// star(h/2, x+(h/2), y+(h/2));
//}
//
//int main(){
//
// int input = 0;
// scanf("%d", &input);
//
// //배열 공백 초기화
// for(int i = 0; i<input; i++)
// {
// for(int j = 0; j < input*2 -1; j++){
// arr[i][j] = ' ';
// }
// }
//
// star(input, input-1, 0);
//
// for(int i = 0; i<input; i++)
// {
// for(int j = 0; j < input*2 -1; j++){
// printf("%c", arr[i][j]);
// }
// printf("\n");
// }
//
// return 0;
//}