File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed
Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change 1+ ```java
2+ import java.io.*;
3+
4+ public class Main {
5+ public static void main(String[] args) throws Exception {
6+ BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+ int N = Integer.parseInt(br.readLine());
8+
9+ if (N == 1) {
10+ System.out.println("*");
11+ return;
12+ }
13+
14+ char[][] map = new char[3 + 4 * (N-1)][1 + 4 * (N-1)];
15+ for (int i = 0; i < 3+4*(N-1); i++) {
16+ for (int j = 0; j < 1+4*(N-1); j++) {
17+ map[i][j] = ' ';
18+ }
19+ }
20+
21+ int r = N * 2;
22+ int c = N * 2 - 2;
23+ int directionR = 1;
24+ int directionC = -1;
25+ int weight = 1;
26+ for (int i = 0; i < 1+4*(N-1); i++) {
27+ if (i % 2 == 0) {
28+ directionR *= -1;
29+ weight += 2;
30+ for (int j = 0; j < weight; j++) {
31+ r = j!=0 ? r + directionR : r;
32+ map[r][c] = '*';
33+ }
34+ } else {
35+ directionC *= -1;
36+ for (int j = 0; j < weight; j++) {
37+ c = j!=0 ? c + directionC : c;
38+ map[r][c] = '*';
39+ }
40+ }
41+ }
42+
43+ BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
44+ for (int i = 0; i < 3+4*(N-1); i++) {
45+ for (int j = 0; j < 1+4*(N-1); j++) {
46+ if (i == 0) {
47+ bw.write("*");
48+ continue;
49+ }
50+ if (i == 1 && j >= 1) continue;
51+ if (j == 4*N - 4) {
52+ bw.write(map[i][j]);
53+ } else {
54+ bw.write(map[i][j]);
55+ }
56+ }
57+ bw.write("\n");
58+ }
59+ bw.flush();
60+ bw.close();
61+ }
62+ }
63+ ```
You can’t perform that action at this time.
0 commit comments