백준 4779 c++

magicdrill·2024년 3월 18일

백준 문제풀이

목록 보기
167/673

백준 4779 c++

#include <iostream>
#include <cmath>

using namespace std;

int input(int lower, int upper);
void cantor(int N);

int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int N = 0;

	while (cin >> N)
	{
		//N = input(0, 12);
		cantor(N);
		cout << "\n";
	}

	return 0;
}

int input(int lower, int upper)
{
	//cout << "input()" << endl;
	int A;

	while (1)
	{
		cin >> A;
		if (A >= lower && A <= upper)
		{
			break;
		}
		else
		{
			;
		}
	}

	return A;
}

void cantor(int N)
{
	int i;

	if (N == 0)
	{
		cout << "-";
		return;
	}
	else
	{
		cantor(N - 1);
		for (i = 0; i < pow(3, N - 1); i++)
		{
			cout << " ";
		}
		cantor(N - 1);
		return;
	}
}

0개의 댓글