#include <iostream>
#include <algorithm>
using namespace std;
int input[105];
int ab[105];
int temp[105];
int index[105];
int cmp(int a,int b)
{
return (a>b);
}
int main()
{
int n;
while(cin>>n&&n>0)
{
for(int i=0;i<n;i++)
{
cin>>input[i];
if(input[i]>0||input[i]==0)
{
ab[i]=input[i];
temp[i]=input[i];
}
else
{
ab[i]=-input[i];
temp[i]=-input[i];
}
}
sort(temp,temp+n,cmp);
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
{
if(temp[i]==ab[j])
{
index[i]=j;
break;
}
}
for(int i=0;i<n-1;i++)
cout<<input[index[i]]<<" ";
cout<<input[index[n-1]]<<endl;
}
}
Hdu:2020 绝对值排序
最新推荐文章于 2018-12-19 13:38:36 发布