码迷,mamicode.com
首页 > 其他好文 > 详细

HDU2673:shǎ崽 OrOrOrOrz

时间:2016-03-22 22:05:33      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

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
5 1 2 3 4 5
 
Sample Output
5 1 4 2 3
 
//大水题。。但是要注意格式
 
 1 #include <iostream>
 2 #include <cstdio>
 3 #include <algorithm>
 4 
 5 using namespace std;
 6 
 7 int main()
 8 {
 9     int n,i;
10     int data[10005];
11     while(cin>>n)
12     {
13         for(i=1;i<=n;i++)
14         scanf("%d",&data[i]);
15         sort(data+1,data+1+n);
16         if(n%2==0)//有偶数个4/2=2 4 1 3 2
17         {
18             for(i=n;i>n/2+1;i--)
19             cout<<data[i]<<" "<<data[n-i+1]<<" ";
20             cout<<data[i]<<" "<<data[n-i+1]<<endl;//否则PE
21         }
22         else//有奇数个 5/2=2 5 1 4 2 3
23         {
24             for(i=n;i>n/2+1;i--)
25             cout<<data[i]<<" "<<data[n-i+1]<<" ";
26             cout<<data[n/2+1]<<endl;
27         }
28 
29 
30     }
31     return 0;
32 }

 

HDU2673:shǎ崽 OrOrOrOrz

标签:

原文地址:http://www.cnblogs.com/nefu929831238/p/5308478.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!