Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
68 lines (57 loc) · 1.93 KB
/
Copy pathMain.java
File metadata and controls
68 lines (57 loc) · 1.93 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
63
64
65
66
67
68
package Java.code;
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int strCount = sc.nextInt(); // 字符串个数
sc.nextLine();
String[] strs = new String[strCount];
for (int i = 0; i < strCount; i++){
strs[i] = sc.nextLine();
}
StringBuilder sb = new StringBuilder();
// 1. 进行切分
for (int i = 0; i < strs.length; i++){
// 遍历每个字符串
char[] ch = strs[i].toCharArray();
if (ch.length < 8){
sb.append(ch);
// 添加字符0
int diff = 8 - ch.length;
for (int j = 0; j < diff; j++){
sb.append('0');
}
}else if (ch.length == 8){
// 长度等于8,不用进行修改
sb.append(ch);
}else{
// 长度大于8
sb.append(strs[i]); // 添加
int diff = 8 - ch.length % 8;
for (int j = 0; j < diff; j++){
sb.append('0');
}
}
}
//每8个字符进行切分
String str = sb.toString();
int counts = str.length()/8;
String[] strings = new String[counts];
for (int i = 0; i < counts; i++){
strings[i] = String.valueOf(sb.substring(i * 8, i* 8 + 8));
}
// 接下来进行排序
for (int i = counts -1; i > 0 ; i--){
for (int j = 0 ; j < i; j++){
if ( strings[j].compareTo(strings[j + 1]) > 0){
String temp = strings[j];
strings[j] = strings[j + 1];
strings[j + 1] = temp;
}
}
}
for (int i = 0; i< counts; i++) {
System.out.print(strings[i] + " ");
}
}
}