forked from Infinite-Loop-KJSIEIT/Practice-Space
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathORDERS.java
More file actions
31 lines (30 loc) · 697 Bytes
/
Copy pathORDERS.java
File metadata and controls
31 lines (30 loc) · 697 Bytes
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
import java.io.*;
import java.util.*;
class ORDERS{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int x;
while(t-- > 0){
int n = sc.nextInt();
int[] sol = new int[n];//soldiers input
int[] rank = new int[n];
for(int i = 0; i < n; i++){
sol[i] = sc.nextInt();
rank[i] = i+1;
}
for(int i = n-1; i >= 0; i--){
int p = i - sol[i];//p points to current position after moving sol[i] places
int temp = rank[p];
for(; p < i; p++){
rank[p] = rank[p+1];//shifting 1 rank ahead
}
rank[p] = temp;
}
for(int i : rank){
System.out.print(i+" ");
}
System.out.print("\n");
}
}
}