728x90
📑문제링크
https://www.acmicpc.net/problem/2447
💻코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
static String[][] arr = null;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int N = Integer.parseInt(br.readLine());
arr = new String[N][N];
printStar(0, 0, N);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
bw.write(arr[i][j] != null ? arr[i][j] : " ");
}
bw.write("\n");
}
bw.flush();
}
private static void printStar(int x, int y, int n) {
if (n == 1) {
arr[x][y] = "*";
return;
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (!(i == 1 && j == 1)) {
printStar(x + i * n / 3, y + j * n / 3, n / 3);
}
}
}
}
}
728x90
'Algorithm > Baekjoon' 카테고리의 다른 글
[Algorithm/Baekjoon] 스카이라인 쉬운거 - 1863 (G4/JAVA) (0) | 2025.06.16 |
---|---|
[Algorithm/Baekjoon] 수 고르기 - 2230 (G5/JAVA) (0) | 2025.05.19 |
[Algorithm/Baekjoon] 1, 2, 3 더하기 7 - 15992 (S1/JAVA) (0) | 2025.05.12 |
[Algorithm/Baekjoon] 카우버거 알바생 - 17208 (G4/JAVA) (0) | 2025.03.10 |
[Algorithm/Baekjoon] 목장 건설하기 - 14925 (G4/JAVA) (0) | 2025.02.12 |