-
Notifications
You must be signed in to change notification settings - Fork 4
/
Main.java
51 lines (47 loc) · 1.41 KB
/
Main.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
49
50
51
import java.util.Arrays;
import java.util.Scanner;
public class Main {
private static int N;
private static int width;
private static int height;
private static char[][] map;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
width = 3 + 4 * (N - 1);
height = N == 1 ? 1: width;
map = new char[height][width + 2];
makeMap();
printMap();
}
private static void printMap() {
for(int i = 0; i < height; ++i){
if(i == 1){
System.out.println(map[1][0]);
continue;
}
for(int j = 0; j < width - 2; ++j){
System.out.print(map[i][j] == '*' ? "*": " ");
}
System.out.println();
}
}
public static void makeMap(){
int pivot = 0;
for(int grid = 0; grid < N; ++grid){
for(int j = pivot; j < width - pivot; j++){
map[pivot][j] = '*';
}
for(int i = pivot; i < height - pivot; ++i){
map[i][pivot] = '*';
}
pivot += 2;
for(int j = width - pivot - 1; j >= pivot - 2; --j){
map[height - pivot + 1][j] = '*';
}
for(int i = pivot; i < height - pivot + 2; ++i){
map[i][width - pivot - 1] = '*';
}
}
}
}