Skip to content

Commit a970397

Browse files
authored
Merge pull request #1477 from AlgorithmWithGod/ksinji
[20251122] BOJ / G5 / 별 찍기 - 10 / 강신지
2 parents 83d46a4 + 29600b1 commit a970397

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main
6+
{
7+
static char[][] star;
8+
9+
public static void main(String[] args) throws Exception{
10+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
StringBuilder sb = new StringBuilder();
12+
int n = Integer.parseInt(br.readLine());
13+
14+
star = new char[n][n];
15+
draw(0, 0, n, false);
16+
17+
for (int i=0; i<n; i++){
18+
for (int j=0; j<n; j++){
19+
sb.append(star[i][j]);
20+
}
21+
sb.append('\n');
22+
}
23+
24+
System.out.print(sb);
25+
}
26+
27+
static void draw(int x, int y, int n, boolean blank){
28+
if (blank){
29+
// 비워야 하는 부분일 경우 한 패턴에 대해 완전 비워야 함
30+
for (int i=x; i<x+n; i++){
31+
for (int j=y; j<y+n; j++){
32+
star[i][j] = ' ';
33+
}
34+
}
35+
return;
36+
}
37+
38+
if (n == 1){
39+
star[x][y] = '*';
40+
return;
41+
}
42+
43+
int pattern = n/3;
44+
int count = 0;
45+
46+
for (int i=x; i<x+n; i+=pattern){
47+
for (int j=y; j<y+n; j+=pattern){
48+
count++;
49+
if (count == 5){
50+
draw(i, j, pattern, true);
51+
} else {
52+
draw(i, j, pattern, false);
53+
}
54+
}
55+
}
56+
}
57+
}
58+
59+
```

0 commit comments

Comments
 (0)