标签:
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 }
标签:
原文地址:http://www.cnblogs.com/nefu929831238/p/5308478.html