From 8ab40da46357fce03c22081a139881641b12d516 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Thu, 21 Aug 2025 22:11:44 +0900 Subject: [PATCH] =?UTF-8?q?[20250821]=20BOJ=20/=20G4=20/=20=EB=B3=84=20?= =?UTF-8?q?=EC=B0=8D=EA=B8=B0=20-=2018=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\263\204 \354\260\215\352\270\260 - 18.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "zinnnn37/202508/21 BOJ G4 \353\263\204 \354\260\215\352\270\260 - 18.md" diff --git "a/zinnnn37/202508/21 BOJ G4 \353\263\204 \354\260\215\352\270\260 - 18.md" "b/zinnnn37/202508/21 BOJ G4 \353\263\204 \354\260\215\352\270\260 - 18.md" new file mode 100644 index 00000000..6a5c2c30 --- /dev/null +++ "b/zinnnn37/202508/21 BOJ G4 \353\263\204 \354\260\215\352\270\260 - 18.md" @@ -0,0 +1,88 @@ +```java +import java.io.*; + +public class BJ_10933_별_찍기_18 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int N; + private static int height; + private static int width; + + private static char[][] mat; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + height = (int) (Math.pow(2, N) - 1); + width = height * 2 - 1; + + mat = new char[height][width]; + } + + private static void sol() throws IOException { + rec(N, 0, 0); + printMat(); + } + + private static void rec(int n, int x, int y) { + if (n == 1) { + mat[x][y] = '*'; + return; + } + + int h = (int) (Math.pow(2, n) - 1); + int w = h * 2 - 1; + + if (n % 2 == 1) { + for (int i = 0; i <= w / 2; i++) { + mat[x + h - i - 1][y + i] = '*'; + mat[x + h - i - 1][y + h * 2 - i - 2] = '*'; + mat[x + h - 1][y + i] = '*'; + mat[x + h - 1][y + h * 2 - i - 2] = '*'; + } + rec(n - 1, x + h / 2, y + w / 4 + 1); + } else { + for (int i = 0; i <= w / 2; i++) { + mat[x][y + i] = '*'; + mat[x][y + h * 2 - i - 2] = '*'; + mat[x + i][y + i] = '*'; + mat[x + i][y + h * 2 - i - 2] = '*'; + } + rec(n - 1, x + 1, y + w / 4 + 1); + } + } + + private static void printMat() throws IOException { + for (char[] chars : mat) { + // 각 줄에서 마지막 '*'의 위치 찾기 + int lastStar = -1; + for (int i = chars.length - 1; i >= 0; i--) { + if (chars[i] == '*') { + lastStar = i; + break; + } + } + + // 마지막 별까지만 출력 + for (int i = 0; i <= lastStar; i++) { + if (chars[i] == '*') { + bw.write('*'); + } else { + bw.write(' '); + } + } + bw.write("\n"); + } + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file