1408191944-hd-shǎ崽 OrOrOrOrz.cpp

来源:互联网 发布:女 欧 t恤 知乎 编辑:程序博客网 时间:2024/05/22 01:28

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.
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

 


 

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;}


 

 

0 0
原创粉丝点击