-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_2447.java
More file actions
94 lines (86 loc) ยท 2.24 KB
/
_2447.java
File metadata and controls
94 lines (86 loc) ยท 2.24 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package backjoon;
// https://www.acmicpc.net/problem/2447
// ๋ณ์ฐ๊ธฐ - 10
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class _2447 {
// ์ ์ญ๋ณ์
static char[][] arr;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
arr = new char[N][N];
// ๋ณ์ฐ๊ธฐ ์ฌ๊ท
star(0, 0, N, false);
//์ถ๋ ฅํ๊ธฐ
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
sb.append(arr[i][j]);
}
sb.append('\n');
}
System.out.print(sb);
}
static void star(int x, int y, int N, boolean blank) {
// ๋น์นธ๋ฃ๊ธฐ
if (blank) {
for (int i = x; i < x + N; i++) {
for (int j = y; j < y + N; j++) {
arr[i][j] = ' ';
}
}
return;
}
// ๋์ด์ ์ชผ๊ฐค ์ ์๋ ๋ธ๋ก์ผ ๋ ๋ณ๋ฃ๊ธฐ
if (N == 1) {
arr[x][y] = '*';
return;
}
int size = N / 3; // 3์ ๋ฐฐ์๋ฅผ 3์ผ๋ก ๋ค ๋๋๋ค.
int count = 0; // ๋ณ ์ถ๋ ฅ ๋์ ์ ์๋ฏธ
for (int i = x; i < x + N; i += size) {
for (int j = y; j < y + N; j += size) {
count++;
if (count == 5) { // 3X3์ธ ๊ฒฝ์ฐ ํญ์ 5๋ฒ์งธ ์นธ์ด ๊ณต๋ฐฑ ์นธ์ด๋ค.
star(i, j, size, true);
} else {
star(i, j, size, false);
}
}
}
}
}
/*
input
27
output
***************************
* ** ** ** ** ** ** ** ** *
***************************
*** ****** ****** ***
* * * ** * * ** * * *
*** ****** ****** ***
***************************
* ** ** ** ** ** ** ** ** *
***************************
********* *********
* ** ** * * ** ** *
********* *********
*** *** *** ***
* * * * * * * *
*** *** *** ***
********* *********
* ** ** * * ** ** *
********* *********
***************************
* ** ** ** ** ** ** ** ** *
***************************
*** ****** ****** ***
* * * ** * * ** * * *
*** ****** ****** ***
***************************
* ** ** ** ** ** ** ** ** *
***************************
*/