-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMain.java
129 lines (114 loc) · 4.11 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// SPDX-License-Identifier: AGPL-3.0-or-later
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public final class Main {
private static final List<Map.Entry<Integer, String>> spis =
List.of(new AbstractMap.SimpleImmutableEntry<>(2, "+---+")
, new AbstractMap.SimpleImmutableEntry<>(1, "/ /|")
, new AbstractMap.SimpleImmutableEntry<>(0, "+---+ |")
, new AbstractMap.SimpleImmutableEntry<>(0, "| | +")
, new AbstractMap.SimpleImmutableEntry<>(0, "| |/")
, new AbstractMap.SimpleImmutableEntry<>(0, "+---+"));
public static int[][] read() {
Scanner input = new Scanner(System.in);
final int m = input.nextInt();
final int n = input.nextInt();
final int[][] will_return = new int[m + 1][n + 1];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
will_return[i][j] = input.nextInt();
}
}
return will_return;
}
public static int[][] reader() throws IOException {
final var input = new Reader();
final int m = input.nextInt();
final int n = input.nextInt();
int[][] will_return = new int[m + 1][n + 1];
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
will_return[i][j] = input.nextInt();
}
}
return will_return;
}
public static void print(char[][] map, int a, int b) {
for (int i = 0; i < spis.size(); i++) {
for (int j = 0; j < spis.get(i).getValue().length();
j++) {
map[a - 1 + i][b + j + spis.get(i).getKey()] = spis.get(i).getValue().charAt(j);
}
}
}
public static void cal(int[][] hi) {
final char[][] out = new char[302][301];
Arrays.stream(out)
.forEach(a -> Arrays.fill(a, '.'));
final int m = hi.length - 1;
final int n = hi[0].length - 1;
final int wide = 4 * n + 2 * m + 1;
int h = -0x3f3f;
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
h = Math.max(h, hi[i][j] * 3 + 2 * (m - i + 1) + 1);
}
}
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < hi[i][j]; k++) {
final int x = h - 3 * (k + 2) - 2 * (m - i) + 1;
final int y = 4 * j + 2 * (m - i - 1) - 1;
print(out, x, y);
}
}
}
output(out, h, wide);
}
public static void main(String[] args) {
final var input = read();
cal(input);
}
public static void output(char[][] map, int high, int wide) {
for (int i = 0; i < high; i++) {
for (int j = 1; j <= wide; j++) {
System.out.print(map[i][j]);
}
System.out.print("\n");
}
}
// refactor from https://github.com/Kattis/kattio/blob/master/Kattio.java
// url: https://raw.githubusercontent.com/Kattis/kattio/master/Kattio.java
// license: MIT
private static final class Reader {
private final BufferedReader br;
private StringTokenizer st;
private Reader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {return Integer.parseInt(next());}
long nextLong() {return Long.parseLong(next());}
double nextDouble() {return Double.parseDouble(next());}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}