Description
明明很喜欢购物,他在双11买了很多物品,每样物品有其价值。明明想知道他买的物品的价值哪个高哪个低,请你帮一下他。
Input
输入包括多组数据。对于每组数据,第一行为整数n(1<=n<=10000)为购买物品的总数。接下来一行n个整数,为每样物品的价值。
Output
对每组数据,按价值由高到低的顺序输出购买物品的编号(编号从0开始)。如果两样物品的价值相同,按购买的先后顺序输出。
Sample Input
3
1 1 1
4
1 2 3 4
Sample Output
0 1 2
3 2 1 0
Hint
请不要使用std:sort()
#include<iostream>
using namespace std;
int a[100000],b[100000];
int n;
void insertsort()//排序
{
for(int i = 1; i < n; i++)
{
for(int j = i; j > 0; j--)
{
if(a[j] > a[j - 1])
{
swap(a[j] , a[j-1]);
swap(b[j], b[j-1]);
}
}
}
}
int main()
{
while(cin >> n)
{
for (int i = 0;i<n;i++)
{
cin >> a[i];
b[i] = i;
}
insertsort();
cout << b[0];
for (int i = 1;i<n;i++)
{
cout << " " << b[i];
}
cout << endl;
}
}