-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMain.java
More file actions
62 lines (53 loc) · 1.75 KB
/
Main.java
File metadata and controls
62 lines (53 loc) · 1.75 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
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
private static int height;
private static int width = 5;
private static int step;
private static char[][] map;
private static ArrayList<Integer> widthGrid;
private static ArrayList<Integer> heightGrid;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
widthGrid = new ArrayList<>();
heightGrid = new ArrayList<>();
height = sc.nextInt();
widthGrid.add(width);
int heightCalculator = 3;
heightGrid.add(heightCalculator);
for(int i = 3; i < height; i *= 2){
step ++;
width = width * 2 + 1;
widthGrid.add(width);
heightCalculator *= 2;
heightGrid.add(heightCalculator);
}
map = new char[height][width];
makeMap(height - 1, width - 1, step);
printMap();
}
public static void makeMap(int y, int x, int step){
if(step == 0){
for(int j = x; j > x - 5; j --){
map[y][j] = '*';
}
map[y - 1][x - 1] = '*';
map[y - 2][x - 2] = '*';
map[y - 1][x - 3] = '*';
} else {
makeMap(y, x, step - 1);
makeMap(y - heightGrid.get(step - 1), x - widthGrid.get(step - 1) / 2 - 1, step - 1);
makeMap(y, x - widthGrid.get(step - 1) - 1, step - 1);
}
}
public static void printMap(){
StringBuilder sb = new StringBuilder();
for(int i = 0; i < height; i ++){
for(int j = 0; j < width; j ++){
sb.append(map[i][j] == '*'? "*": " ");
}
sb.append("\n");
}
System.out.println(sb.toString());
}
}