Notice
Recent Posts
Recent Comments
05-21 07:17
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

Byeol Lo

N4779 - 칸토어 집합 본문

Algorithm/DevideConquer & Recursion

N4779 - 칸토어 집합

알 수 없는 사용자 2023. 12. 11. 14:00
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;


public class Main {
    private static final BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter BW = new BufferedWriter(new OutputStreamWriter(System.out));
    private static final StringBuffer SB = new StringBuffer("");

    public static void main(String[] args) throws IOException {
        input();
        BW.write(SB.toString());
        BR.close();
        BW.close();
    }

    private static void input() throws IOException {
        String i = "";
        while((i = BR.readLine()) != null)
            SB.append(solution(Integer.parseInt(i))).append("\n");
    }

    private static String solution(int n) {
        if(n==0) return "-";
        else if(n==1) return "- -";
        else {
            int tmp = (int) Math.pow(3, n-1);
            return solution(n-1) + " ".repeat(tmp) + solution(n-1);
        }
    }
}

 

'Algorithm > DevideConquer & Recursion' 카테고리의 다른 글

N11729 - 하노이 탑 이동 순서  (0) 2023.12.11
N2447 - 별 찍기 - 10  (0) 2023.12.11
Comments