I need to know how to print the permutation when I input something such as X = [5 0 1 1 1 2]
where 5 = n
aka the number of integers following in the array. The output is simple, it'd be J = [5 1 2 4 3]
. That is obtained by reading X from the end starting at 2. There are 3 numbers in N (1-5) larger than 2. So J[5]
is now 3. Then move in X to the 1 before the 2, there is 1 number in (1-5) - (3(obtained earlier)) in front larger than J[4]
so J[4] = 4
. If that doesn't make sense because of my explanation this might help, when 3 was removed it is now 1 2 4 5. So if there is to be only 1 element larger than itself it has to be the element 4 because only 5 is larger. I have this so far and I'm confusing myself over coding something that seems so simple.
public static void main(String[] args) {
int i;
int j;
Scanner input = new Scanner(System.in);
int nums = input.nextInt();
if (nums < 1 || nums > 1000) {
input.close();
} else {
for (int counter = 0; counter < nums; counter++) {
int[] a = new int[nums];
int[] w = new int[nums];
}
}
}