File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
6+ static char [][] map;
7+
8+ public static void main (String [] args ) throws Exception {
9+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
10+ int n = Integer . parseInt(br. readLine(). trim());
11+ int w = 2 * n - 1 ;
12+
13+ map = new char [n][w];
14+ for (int i = 0 ; i < n; i++ ) Arrays . fill(map[i], ' ' );
15+
16+ draw(0 , n - 1 , n);
17+
18+ StringBuilder sb = new StringBuilder (n * (w + 1 ));
19+ for (int i = 0 ; i < n; i++ ) {
20+ sb. append(map[i]). append(' \n ' );
21+ }
22+ System . out. print(sb);
23+ }
24+
25+ static void draw (int r , int c , int size ) {
26+ if (size == 3 ) {
27+ map[r][c] = ' *' ;
28+ map[r + 1 ][c - 1 ] = ' *' ;
29+ map[r + 1 ][c + 1 ] = ' *' ;
30+ for (int d = - 2 ; d <= 2 ; d++ ) map[r + 2 ][c + d] = ' *' ;
31+ return ;
32+ }
33+
34+ int h = size / 2 ;
35+ draw(r, c, h);
36+ draw(r + h, c - h, h);
37+ draw(r + h, c + h, h);
38+ }
39+ }
40+
41+ ```
You can’t perform that action at this time.
0 commit comments