문제 링크입니다: https://www.acmicpc.net/problem/10994
10994번: 별 찍기 - 19
예제를 보고 규칙을 유추한 뒤에 별을 찍어 보세요.
www.acmicpc.net
N 번째 모양이 N + 1 번째 모양 가운데 오기 때문에 재귀함수를 통해 구현해주면 되는 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int MAX = 100 * 4 + 1; | |
char starMap[MAX][MAX]; | |
void func(int y, int x, int depth) | |
{ | |
if (depth == 1) | |
{ | |
starMap[y][x] = '*'; | |
return; | |
} | |
for (int i = 0; i < 4 * (depth - 1) + 1; i++) | |
{ | |
if (i == 0 || i == 4 * (depth - 1)) | |
{ | |
for (int j = 0; j < 4 * (depth - 1) + 1; j++) | |
{ | |
starMap[y + i][x + j] = '*'; | |
} | |
continue; | |
} | |
starMap[y + i][x] = '*'; | |
starMap[y + i][x + 4 * (depth - 1)] = '*'; | |
} | |
func(y + 2, x + 2, depth - 1); | |
return; | |
} | |
int main(void) | |
{ | |
int N; | |
cin >> N; | |
func(0, 0, N); | |
for (int i = 0; i < 4 * (N - 1) + 1; i++) | |
{ | |
for (int j = 0; j < 4 * (N - 1) + 1; j++) | |
{ | |
char c = starMap[i][j] == '*' ? '*' : ' '; | |
cout << c; | |
} | |
cout << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 13015번 별 찍기 - 23 (0) | 2020.04.10 |
---|---|
백준 10997번 별 찍기 - 22 (0) | 2020.04.09 |
백준 10993번 별 찍기 - 18 (0) | 2020.04.07 |
백준 10899번 King of penalty (0) | 2020.04.07 |
백준 16198번 에너지 모으기 (0) | 2020.04.07 |