简单的排序,注意输出即可
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int a[10001];
int n,i;
//int t = 0;
while(cin>>n)
{
//if(t)cout<<endl;
//t++;
for(i=0; i<n; i++)
{
cin>>a[i];
}
sort(a,a+n);
if(n%2==1)
{
for(i=0; i<=(n-2)/2; i++)
cout<<a[n-i-1]<<" "<<a[i]<<" ";
cout<<a[i];
}
else
{
for(i=0; i<=(n-2)/2; i++)
{
if(i==(n-1)/2)
cout<<a[n-i-1]<<" "<<a[i];
else
{
cout<<a[n-i-1]<<" "<<a[i]<<" ";
}
}
}
cout<<endl;}
return 0;
}
hdu 1.3.4 shǎ崽 OrOrOrOrz
时间: 2024-10-01 02:50:59