-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay77.java
More file actions
64 lines (64 loc) · 1.4 KB
/
Copy pathDay77.java
File metadata and controls
64 lines (64 loc) · 1.4 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
import java.util.*;
public class Day77{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int tc = in.nextInt();
int master[] = new int[100];
Arrays.fill(master,0);
for (int i=0;i<tc ;i++ ) {
int size = in.nextInt();
int disks[] = new int[size];
for (int j=0;j<size ;j++ ) {
disks[j] = in.nextInt();
}
int index,count=0;
for (int j=0;j<size ;j++ ) {
if (j==0) {
master[j] = disks[j];
count++;
}else{
index=0;
while (true) {
if (master[index]==0) {/*like creating a new stack dynamically*/
master[index] = disks[j];
count++;
break;
}else if (disks[j]>master[index]) {
index+=10;
}else{
int head=0,hi=0;
for (int x=index;x<100 ;x++ ) {
if (master[x]==0) {
head = master[x-1];/*finding the head of each stack*/
hi = x;
break;
}
}
if (head>disks[j]) {
master[hi] = disks[j];
}else{
index+=10;
}
if (head>disks[j]) {
break;
}
}
}
}
}
System.out.println("Output");
System.out.print(count+" ");
int x = 0;
for (int j=0;j<count ;j++ ) {
while(true){
if (master[x]==0) {
System.out.print(master[x-1]+" ");
break;
}
x++;
}
x=10*(j+1);
}
}
}
}