Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

22.01.19 - [BOJ] 17478. 재귀함수가 뭔가요? #198

Closed
suhyunsim opened this issue Jan 19, 2022 · 0 comments
Closed

22.01.19 - [BOJ] 17478. 재귀함수가 뭔가요? #198

suhyunsim opened this issue Jan 19, 2022 · 0 comments
Assignees
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀

Comments

@suhyunsim
Copy link
Owner

문제

핵심 아이디어

어려운 점, 실수

  • 풀긴 풀었는데 맞았다고 할 수 있나...

풀이

package main.java.com.poogle.BOJ.Q17478;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        System.out.println("어느 한 컴퓨터공학과 학생이 유명한 교수님을 찾아가 물었다.");
        calculate(n);
    }

    static String c = "";

    private static void calculate(int n) {
        String underBar = c;
        if (n == 0) {
            System.out.println(underBar + "\"재귀함수가 뭔가요?\"");
            System.out.println(underBar + "\"재귀함수는 자기 자신을 호출하는 함수라네\"");
            System.out.println(underBar + "라고 답변하였지.");
            return;
        }
        System.out.println(underBar + "\"재귀함수가 뭔가요?\"");
        System.out.println(underBar + "\"잘 들어보게. 옛날옛날 한 산 꼭대기에 이세상 모든 지식을 통달한 선인이 있었어.");
        System.out.println(underBar + "마을 사람들은 모두 그 선인에게 수많은 질문을 했고, 모두 지혜롭게 대답해 주었지.");
        System.out.println(underBar + "그의 답은 대부분 옳았다고 하네. 그런데 어느 날, 그 선인에게 한 선비가 찾아와서 물었어.\"");
        c += "____";
        calculate(n - 1);
        System.out.println(underBar + "라고 답변하였지.");
    }
}
@suhyunsim suhyunsim added 성공 맞은 문제 실버 BOJ - 실버 재귀 labels Jan 19, 2022
@suhyunsim suhyunsim added this to the 1월 3주 차 milestone Jan 19, 2022
@suhyunsim suhyunsim self-assigned this Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
성공 맞은 문제 실버 BOJ - 실버 재귀
Projects
None yet
Development

No branches or pull requests

1 participant