본문 바로가기

알고리즘/백준

별 찍기 - 10

#include <iostream>
using namespace std;

char arr[3000][3000];

void empty(int num)      // 빈 공간 생성

{
	for (int i = 0; i < num; i++) 
		for (int j = 0; j < num; j++) 
			arr[i][j] = ' ';
}

void draw(int num, int x, int y) //별 그리기
{

	if (num == 1) 
	{     
		arr[x][y] = '*';
		return;
	}

	int N = num / 3; //3으로 나눔

	for (int i = 0; i < 3; i++) 
	{
		for (int j = 0; j < 3; j++) 
		{
			if (i == 1 && j == 1)  
				continue;                  // i가 1이고 j가 1이면 공백
			draw(N, x + (N * i), y + (N * j)); 
		}
	}
}

int main()
{
	int num;
	cin >> num;

	empty(num);
	draw(num, 0, 0);

	for (int i = 0; i < num; i++) //출력
	{     
		for (int j = 0; j < num; j++) 
			cout << arr[i][j];
		cout << endl;
	}
	return 0;
}

'알고리즘 > 백준' 카테고리의 다른 글

아스키 코드  (0) 2019.10.07
하노이 탑 이동 순서  (0) 2019.10.06
팩토리얼  (0) 2019.10.03
한수  (0) 2019.09.29
셀프 넘버  (0) 2019.09.28