shǎ崽 OrOrOrOrz |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 3853 Accepted Submission(s): 1193 |
|
Problem Description 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.
|
Input There are multiple test cases, each case begins with one integer N(1 <= N <= 10000), following N distinct integers.
|
Output Output a sequence of distinct integers described above.
|
Sample Input 51 2 3 4 5
|
Sample Output 5 1 4 2 3
|
题目大意
给你一个不同的整数序列,依次输出号码如下:首先选择最大的,然后第二的最小,最大,最小二等选择所有的号码。
注意事项
要注意给出的长度是奇数还是偶数,分别考虑。
代码
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[11000];
int main()
{
int n;
int i,j,k;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&s[i]);
sort(s,s+n);
k=n/2;
for(i=0,j=n-1;i<k;i++,j--)
{
printf("%d %d",s[j],s[i]);
if(i!=k-1)
printf(" ");
}
if(n%2==1)//长度是奇数的时候要另外考虑
printf(" %d",s[k]);
printf("\n");
}
return 0;
}