-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJ02032.java
43 lines (41 loc) · 1.28 KB
/
J02032.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
import java.util.*;
public class J02032 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int test = in.nextInt();
while (test-->0) {
int n = in.nextInt();
int a[] = new int[1001];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
int k = 1;
Stack<String> mys = new Stack<>();
for (int i = 0; i < n; i++) {
boolean ok = true;
for (int j = 0; j < n - 1; j++) {
if (a[j] > a[j + 1]) {
int t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
ok = false;
}
}
if (!ok) {
k++;
String s = "";
for (int h = 0; h < n; h++) {
s += Integer.toString(a[h]);
s += " ";
}
mys.push(s);
}
}
for (int i = k - 1; i >= 1; i--) {
System.out.print("Buoc " + i + ": ");
System.out.println(mys.peek());
mys.pop();
}
}
}
}