forked from upupming/algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1031 Hello World for U (20).java
36 lines (35 loc) · 1.21 KB
/
1031 Hello World for U (20).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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
final char[] chars = reader.readLine().toCharArray();
final int length = chars.length + 2;
final int rows = length / 3;
final int columns = length / 3 + length % 3;
final char[][] table = new char[rows][columns];
int index = 0;
//left
for (int i = 0; i < rows; i++, index++) {
table[i][0] = chars[index];
}
//bottom
for (int i = 1; i < columns - 1; i++, index++) {
table[rows - 1][i] = chars[index];
}
//right
for (int i = rows - 1; i >= 0; i--, index++) {
table[i][columns - 1] = chars[index];
}
for (int i = 0; i < rows; i++) {
for (int j = 0; j < columns; j++) {
char c = table[i][j] == 0 ? ' ' : table[i][j];
System.out.printf("%c", c);
if (j == columns - 1) {
System.out.println();
}
}
}
}
}