티스토리 뷰

PS/boj

boj)2447 - 별 찍기 - 10

kingsubin 2020. 11. 14. 12:15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import 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(00length);
 
        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 condition
        if (length == 1return;
 
        // mark
        if (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] = '*';
                }
            }
        }
 
        // recursion
        int 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 == 1return;
 
        for (int i = x; i < x + length; i++) {
            for (int j = y; j < y + length; j++) {
                map[i][j] = ' ';
            }
        }
    }
}
 
cs
 

 

 

- 재귀

 

- 다른 사람들 풀이보다 길고 돌아서 푼거 같지만 나름 만족 ...

 

 


www.acmicpc.net/problem/2447

'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