-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2447.java
49 lines (40 loc) · 1.37 KB
/
2447.java
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
import java.io.*;
import java.util.*;
public class MakeStar {
static char[][] stars;
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
stars = new char[N][N];
recursion(N, 0, 0, false);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < N; i++) {
for(int j = 0; j < N; j++) {
sb.append(stars[i][j]);
}
sb.append("\n");
}
System.out.println(sb);
}
public static void recursion(int n, int Y, int X, boolean vacant) {
if(n <= 3) {
for(int i = Y; i < Y + 3; i++) {
for(int j = X; j < X + 3; j++) {
if(vacant) stars[i][j] = ' ';
else {
if(i == Y + 1 && j == X + 1) stars[i][j] = ' ';
else stars[i][j] = '*';
}
}
}
return;
}
int interval = n / 3;
for(int y = Y; y < Y + n; y += interval) {
for(int x = X; x < X + n; x += interval) {
if(y == Y + interval && x == X + interval) recursion(interval, y, x, true);
else recursion(interval, y, x, vacant);
}
}
}
}