백준 17478 c++

magicdrill·2024년 4월 12일

백준 문제풀이

목록 보기
295/673

백준 17478 c++

#include <iostream>
#include <string>

using namespace std;

int N;

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 print_dash(int t)
{
	int i;

	for (i = 0; i < t; i++)
	{
		cout << "____";
	}

	return;
}

void recursion_function(int t)
{
	if (t == N)
	{
		print_dash(t);
		cout << "\"재귀함수가 뭔가요?\"\n";
		print_dash(t);
		cout << "\"재귀함수는 자기 자신을 호출하는 함수라네\"\n";
		print_dash(t);
		cout << "라고 답변하였지.\n";
		return;
	}
	else
	{
		print_dash(t);
		cout << "\"재귀함수가 뭔가요?\"\n";
		print_dash(t);
		cout << "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.\n";
		print_dash(t);
		cout << "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.\n";
		print_dash(t);
		cout << "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"\n";
		recursion_function(t + 1);
		print_dash(t);
		cout << "라고 답변하였지.\n";
		return;
	}
}

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

	N = input(1, 50);

	cout << "어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.\n";
	recursion_function(0);

	return 0;
}

0개의 댓글