hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #inversion #293

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);

    int n = scanner.nextInt();

    int arr[] = new int[n];
    for (int i = 0; i < n; i++) {
        arr[i] = scanner.nextInt();
    }
    int oriArr[] = new int[n];
    int count = -1;
    int ans = 0;
    int x = 0;

    while (true) {

        for (int i = 0; i < n; i++) {

            if (oriArr[i] == 0) {
                count++;
            }

            if (count == arr[ans]) {
                oriArr[i] = ans++ + 1;
                count = -1;
                x++;
                break;
            }
        }

        if (x ==n ) {
            for(int i=0; i<n; i++) {
                System.out.print(oriArr[i]+ " ");
            }
            break;
        }
    }

}

}