
#include <iostream>
#define MAX 2*(3072)
char stars[MAX/2][MAX];
void star(int n, int x, int y){
if(n == 3){
stars[y][x] = '*';
stars[y+1][x-1] = '*';
stars[y+1][x+1] = '*';
stars[y+2][x-2] = '*';
stars[y+2][x-1] = '*';
stars[y+2][x] = '*';
stars[y+2][x+1] = '*';
stars[y+2][x+2] = '*';
return;
}
star(n/2, x, y);
star(n/2, x - n/2, y + n/2);
star(n/2, x + n/2, y + n/2);
}
int main(int argc, char **argv){
int N;
scanf("%d",&N);
for(int i=0; i<N; i++){
for(int j=0; j<N * 2; j++){
if(j == N * 2 - 1){
stars[i][j] = '\0';
} else {
stars[i][j] = ' ';
}
}
}
star(N, N-1, 0);
for(int i=0; i<N; i++){
for(int j=0; j< N * 2 - 1; j++){
printf("%c", stars[i][j]);
}
printf("\n");
}
return 0;
}
오늘의 키포인트
- 첫 골드 문제. 복습 필요. 너무너무 안풀려서 인터넷을 많이 참고하였다.
- 그냥 별을 찍는것이 아니라 모두 배열에 넣는 것이 핵심.
- 별의 시작점을 이용한다.
- 삼각형을 모은 것들이 되풀이 되므로 재귀함수를 호출해야한다.