// 칸토어 집합
package Silver_III_3;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ex4779 {
public static void main(String[] args) throws IOException {
// 칸토어 집합 계산 코드
String[] cantorSet = new String[13];
cantorSet[0] = "-";
for (int i = 1; i <= 12; i++) {
cantorSet[i] = cantorSet[i - 1]
+ String.format("%" + Math.pow(3, i - 1) + "s", " ")
+ cantorSet[i - 1];
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = "";
// 입력 없을 떄까지 반복
while ((input = br.readLine()) != null && !input.isEmpty()) {
int n = Integer.parseInt(input);
System.out.println(cantorSet[n]);
}
}
}
메모이제이션 방식으로 풀었다.
'백준 풀이 > 자바(Java)' 카테고리의 다른 글
백준 10545 자바 - 뚜기뚜기메뚜기 (0) | 2024.08.13 |
---|---|
백준 27939 자바 - 가지 교배 (0) | 2024.08.13 |
백준 6986 자바 - 절사평균 (0) | 2024.08.10 |
백준 30823 자바 - 건공문자열 (0) | 2024.08.08 |
백준 5179 자바 - 우승자는 누구? (0) | 2024.08.07 |