Internal sorting of data structures---cross-sorting (Nothing special!!!) )

Source: Internet
Author: User

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!!!) )

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.