Cross sort Time limit:1000ms Memory limit:32768k The title describes the number of inputs n, the order of all odd positions from small to large, and the number of even positions from the large to the small. The first line of input input is a positive integerN (2<=n<=100).
The second line is n a space-separated integer. Output output is only one rowThe number of n is the sequence ordered by the requirement, separated by a space. Sample input
61 2 3 4 5 6
Sample output
1 6 3 4 5 2
#include <iostream> #include <string> #include <stdio.h> #include <string.h> #include < Algorithm>using namespace Std;int cmp (int a, int b) { return a>b;} int main () { unsigned int n; int a[100], e=0; int b[100], d=0; int I, J; cin>>n; int DD; for (I=1; i<=n; i++) { cin>>dd; if (i%2==1) a[e++]=dd; else b[d++]=dd; } Sort (A, a+e); Sort (b, b+d, CMP); if (n%2==0) {for (i=0; i< (N/2); i++) { if (i==0) cout<<a[i]<< "" <<b[i ]; else cout<< "" <<a[i]<< "" <<b[i]; } cout<<endl; } else {for (i=0; i< (N/2); i++) { cout<<a[i]<< "" <<b[i]<< ""; } cout<<a[e-1]<<endl; } return 0;}
Internal sorting of data structures---cross-sorting (Nothing special!!!) )