728x90
17478번: 재귀함수가 뭔가요?
평소에 질문을 잘 받아주기로 유명한 중앙대학교의 JH 교수님은 학생들로부터 재귀함수가 무엇인지에 대하여 많은 질문을 받아왔다. 매번 질문을 잘 받아주셨던 JH 교수님이지만 그는 중앙대
www.acmicpc.net
package 백준renew;
import java.io.*;
import java.util.*;
public class 실버1_17478_재귀함수가뭔가요 {
static int N;
static StringBuilder sb = new StringBuilder();
static String sentences[] = {"\"재귀함수가 뭔가요?\"", "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어."
,"마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.", "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\""
,"라고 답변하였지."};
static String answer[] = {"\"재귀함수가 뭔가요?\"", "\"재귀함수는 자기 자신을 호출하는 함수라네\"", "라고 답변하였지."};
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
First();
Go(N, 1);
System.out.println(sb.toString());
}
static void First() {
sb.append("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.").append('\n');
}
static void Go(int N, int count) {
for(int i=0; i<sentences.length; i++) {
underBar(count);
sb.append(sentences[i]).append('\n');
if(i == 3) {
if(N == count) {
Answer(count);
}else {
Go(N, count+1);
}
}
if(i == 4) {
return;
}
}
}
static void underBar(int count) {
if(count-1 == 0) {
return;
}
for(int i=0; i<4*(count-1); i++) {
sb.append("_");
}
}
static void Answer(int count) {
for(int i=0; i<answer.length; i++) {
underBar(count+1);
sb.append(answer[i]).append('\n');
}
}
}
728x90
'코테 > Algorithm' 카테고리의 다른 글
[Programmers] PCCE 기출문제 10번 데이터 분석 (JAVA) (0) | 2024.02.09 |
---|---|
[Programmers] PCCE 기출문제 9번 이웃한 칸 (JAVA) (1) | 2024.02.09 |
[Programmers] Lv1. 둘만의 암호 (JAVA) (1) | 2024.02.08 |
[BOJ] 1697: 숨바꼭질 (JAVA) (0) | 2024.02.06 |
[BOJ] 21736: 헌내기는 친구가 필요해 (JAVA) (1) | 2024.02.06 |