2014
02-12

# shǎ崽 OrOrOrOrz

Acmer in HDU-ACM team are ambitious, especially shǎ崽, he can spend time in Internet bar doing problems overnight. So many girls want to meet and Orz him. But Orz him is not that easy.You must solve this problem first.
The problem is :
Give you a sequence of distinct integers, choose numbers as following : first choose the biggest, then smallest, then second biggest, second smallest etc. Until all the numbers was chosen .
For example, give you 1 2 3 4 5, you should output 5 1 4 2 3

There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.

There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.

5
1 2 3 4 5

5 1 4 2 3

#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int n;
while (scanf("%d",&n)!=EOF)
{
int a[10010];
for (int i=0; i<n; i++)
scanf("%d",&a[i]);
sort(a,a+n);
int begin=0,end=n-2,flag=1;
printf("%d",a[n-1]);
while (begin<=end)
{
if (flag) {printf(" %d",a[begin]); begin++;}
else {printf(" %d",a[end]); end--;}
flag^=1;
}
printf("\n");
}
return 0;
}