
소스코드:
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
public class Main {
static BufferedReader br;
static BufferedWriter bw;
static int N;
static char[][] board;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
bw = new BufferedWriter(new OutputStreamWriter(System.out));
N = Integer.parseInt(br.readLine());
br.close();
board = new char[N][N * 2 - 1];
for (int i = 0; i < N; i++) {
Arrays.fill(board[i], ' ');
}
solve(0, N - 1, N);
for (int i = 0; i < N; i++) {
bw.write(board[i]);
bw.newLine();
}
bw.close();
}
public static void solve(int y, int x, int size) {
if (size == 3) {
board[y][x] = '*';
board[y + 1][x - 1] = '*';
board[y + 1][x + 1] = '*';
for (int i = 0; i < 5; i++) {
board[y + 2][x - 2 + i] = '*';
}
return;
}
int newSize = size / 2;
solve(y, x, newSize);
solve(y + newSize, x - newSize, newSize);
solve(y + newSize, x + newSize, newSize);
}
}
글의 내용 중 잘못된 점이나 수정이 필요한 부분, 혹은 궁금한 사항이 있다면 언제든 댓글로 남겨주시면 감사하겠습니다.
여러분의 피드백은 더 나은 글을 작성하는 데 큰 도움이 됩니다. 감사합니다.
'알고리즘 > 백준' 카테고리의 다른 글
| [JAVA-자바] 9663번: N-Queen (0) | 2025.05.09 |
|---|---|
| [JAVA-자바] 5639번: 이진 검색 트리 (0) | 2025.05.08 |
| [JAVA-자바] 1987번: 알파벳 (0) | 2025.05.03 |
| [JAVA-자바] 1967번: 트리의 지름 (0) | 2025.05.03 |
| [JAVA-자바] 1753번: 최단경로 (0) | 2025.05.02 |