forked from apachecn/apachecn-algo-zh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzhaoyinwangluokeji.java
42 lines (36 loc) · 1.28 KB
/
zhaoyinwangluokeji.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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Helper(n);
}
private static void Helper(int n) {
int count = 90;
int start = 1;
String res = "";
// System.out.print((count * 1.0 - (count-1)*count/2.0)/count);
while ((count * 1.0 - (count-1)*count/2.0)/count < start*1.0){
for (int i = 0; i <= n / count; i++) {
if (count * i + (count-1) * count /2.0 == n) {
System.out.print("[");
res += "[";
for (int j =i; j <= i+count-1; j++){
if (j==i+count-1){
System.out.println(j+"]");
res += Integer.toString(j) + "]";
break;
}
System.out.print(j+", ");
res += Integer.toString(j) + ", ";
}
// System.out.print("]");
// System.out.println("");
}
}
count -= 1;
}
res = new StringBuffer(res).reverse().toString();
// System.out.print(res);
}
}