Amrish is a brilliant student who has a huge interest in coding. So his friend Dev gave an array A of non-negative integers of size m to Amrish and also you.
So your task is to sort the array in non-decreasing order and print out the original indices of the new sorted array.
Assume the input array as A = { 4, 5, 3, 7, 1 }. ( indices = { 0, 1, 2, 3, 4 } )
After sorting the new array becomes A = { 1, 3, 4, 5, 7 }. ( indices = { 4, 2, 0, 1, 3 } )
The required output should be “4 2 0 1 3” (Without Quotes), these are the original indices.
NOTE: The indexing of the array starts with 0.
Input:
The first line of input consists of the size of the array
The next line consists of the array of size m
Output:
Output consists of a single line of integers
#include <stdio.h> int main() { int n,a[100],b[100],i,j,t; scanf("%d",&n); n=n+1; for(i=0;i<n-1;i++) { scanf("%d",&a[i]); b[i]=a[i]; } for(i=0;i<n-1;i++) { for(j=i+1;j<n-1;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; }}} for(i=0;i<n-1;i++) { for(j=0;j<n-1;j++) if(a[i]==b[j]) printf("%d ",j); } return 0; }
INPUT_1:
7
18 45 98 30 12 85 6
OUTPUT:
6 4 0 3 1 5 2
INPUT_2:
8
8 2 7 9 17 36 22 90
OUTPUT:
1 2 0 3 4 6 5 7
INPUT_3:
5
5 4 2 1 3
OUTPUT:
3 2 4 1 0
INPUT_4:
10
11 55 99 5 2 0 1 5 6 78
OUTPUT:
5 6 4 3 7 3 7 8 0 1 9 2
ILLUSTRATION
Morae Q!
- Find the number of strings made by using each alphabet as starting character.
- Find the Pythagorean triplet.
- Find out what is the minimum possible energy he needs to spend.
- Sort the array in non-decreasing order and print out the original indices of sorted array.
- Compute the number of landmasses on the planet after all the meteorites have fallen.
- Give the appropriate server status as output.
- Regular expressions (Regex) using search module in python.
- Find the minimum distance between any pair of equal elements in the array.
- Find the total number of matching pairs of socks that are available.
- Find the total number of teams which can work together and cannot work together.
- Given the heights of all the boys and girls tell whether it is possible for all boys to get a girl.
- Find the sequence of cities to visit according to coordinates and conditions.
- Find the number of unique patches of rectangular land to grow samba(rice) in.
- Regular expression Regex matching strings.
- Generate a greeting quote for admin.
- Find all the cavities on the map and replace their depths with the character X.
- Check whether the given graph is Bipartite or not.
- Find the status of the passengers and safari cars at zoo after k units of time.
- Determine the chair number occupied by the child who will receive that chocolate.
- Check if Rubik’s cube of any dimensions can be assembled.