-
boj)2447 - 별 찍기 - 10PS/boj 2020. 11. 14. 12:1512345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364import java.io.*;import java.util.Scanner;public class boj_2447 {static char[][] map;static int length;static Scanner sc = new Scanner(System.in);static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));public static void main(String[] args) throws IOException {length = sc.nextInt();map = new char[length][length];func(0, 0, length);for (int i = 0; i < length; i++) {for (int j = 0; j < length; j++) {bw.write(map[i][j]);}bw.newLine();}bw.flush();bw.close();}static void func(int x, int y, int length) {// base conditionif (length == 1) return;// markif (length == 3) {for (int i = x; i < x + length; i++) {for (int j = y; j < y + length; j++) {if (i == x + 1 && j == y + 1) map[i][j] = ' ';else map[i][j] = '*';}}}// recursionint newLength = length/3;for (int i = 0; i < 3; i++) {for (int j = 0; j < 3; j++) {if (i == 1 && j == 1) {printSpace(x + newLength * i, y + newLength * j, newLength);} else {func(x + newLength * i, y + newLength * j, newLength);}}}}static void printSpace(int x, int y, int length) {if (length == 1) return;for (int i = x; i < x + length; i++) {for (int j = y; j < y + length; j++) {map[i][j] = ' ';}}}}
cs - 재귀
- 다른 사람들 풀이보다 길고 돌아서 푼거 같지만 나름 만족 ...
'PS > boj' 카테고리의 다른 글
boj)15649 - N과 M (1) (0) 2020.11.16 boj)5904 - Moo 게임 (0) 2020.11.15 boj)16505 - 별 (0) 2020.11.14 boj)1992 - 쿼드트리 (0) 2020.11.13 boj)1780 - 종이의 개수 (0) 2020.11.13