Repository navigation
Expand file tree
/
Copy pathBOJ_2447.java
More file actions
60 lines (46 loc) · 1.48 KB
/
Copy pathBOJ_2447.java
File metadata and controls
60 lines (46 loc) · 1.48 KB
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
package baekjoon.silver;
import java.io.*;
public class BOJ_2447 {
public static char[][] matrix;
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());
// 풀이
matrix = new char[n][n];
fillMatrix(0, 0, n, false);
// 출력
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
bw.write(matrix[i][j]);
}
bw.write("\n");
}
bw.flush();
bw.close();
}
public static void fillMatrix(int x, int y, int n, boolean flag) { // x, y : 좌표, n : 블록의 길이, flag : 공백 여부
if(flag) {
for (int i = x; i < x + n; i++) {
for (int j = y; j < y + n; j++) {
matrix[i][j] = ' ';
}
}
return;
}
if(n == 1) {
matrix[x][y] = '*';
return;
}
// 블록이 더 나누어지는 경우
int size = n / 3;
int count = 0; // count = 5인 경우, 공백에 해당함
for (int i = x; i < x + n; i += size) {
for (int j = y; j < y + n; j += size) {
count++;
fillMatrix(i, j, size, count == 5);
}
}
}
}