ACM水题系列 HDOJ2673

来源:互联网 发布:gta5女人物捏脸数据 编辑:程序博客网 时间:2024/05/18 01:11

shǎ崽 OrOrOrOrz

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 4085 Accepted Submission(s): 1264 
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 <iostream>#include <vector>#include <algorithm>using namespace std;int main(){    int t,a[10001];    while(cin>>t){        for(int i=0;i<t;i++)            cin>>a[i];        sort(a,a+t);        int flag = t-1,sum =1;        for(int i=0;i<t;i++,sum++){            if(i%2 == 0){                if(sum == t) cout<<a[flag]<<endl;                else cout<<a[flag]<<" ";                flag--;            }            else{                if(sum == t) cout <<a[i/2]<<endl;                else cout<<a[i/2]<<" ";            }        }    }    return 0;}


0 0
原创粉丝点击