-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_array2.c
87 lines (59 loc) · 2.12 KB
/
list_array2.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Students of class CSE are given an array A of positive integers of size N. The student’s task is to sort the array in increasing order and print out the original index position of the new sorted array.
// NOTE: The indexing of the array starts with 0.
// Example:
// A={4,5,3,7,1}
// After sorting the new array becomes A={1,3,4,5,7}.
// The required output should be "4 2 0 1 3"
// INPUT :
// The first line of input consists of the size of the array A
// The next line consists of the array of size N
// OUTPUT :
// Output consists of a single line of integers
// CONSTRAINTS:
// 1<=N<=10^6
// 0<=A[i]<=10^6
// Sample Input 1
// Input:
// 5
// 12 3 87 14 65
// Output:
// 1 0 3 4 2
// Sample Input 2
// Input:
// 7
// 12 23 32 45 56 67 89
// Output:
// 0 1 2 3 4 5 6
#include <stdio.h>
int main()
{
long int n;
scanf("%ld", &n);
long int arr[n], ind[n];
for (int i = 0; i < n; i++)
{
scanf("%ld", &arr[i]);
ind[i] = i;
}
long int i, j;
for (i = 0; i < n - 1; i++)
{
for (j = i + 1; j < n; j++)
{
long int temp, tempi;
if (arr[i] > arr[j])
{
tempi = ind[i];
ind[i] = ind[j];
ind[j] = tempi;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (int i = 0; i < n; i++)
{
printf("%ld ", ind[i]);
}
}