1042: Clown Sort

Source: Internet
Author: User

1042: Clown Sort time limit: 1 Sec memory limit: MB
Submitted by: 149 Resolution: 121
Submitted State [Discussion Version] The title describes you in the Albatross circus (yes, it is made up of a bunch of clowns) to do management work, and you just finished writing a program whose output is to arrange their names in a non-descending way by length, with a list of names (so that each is at least as long as it precedes). However, your boss doesn't like this output, but wants the output to appear more symmetrical, shorter strings at the top and bottom, and longer strings in the middle. His rule is that each pair of names is at the opposite ends of the list, and the first name in the group is always at the top of the list. For example, in the first example below, Bo and Pat are the first pair, and Jean and Kevin are the second pair, and so on. The input input consists of 1 to multiple string collections, the last behavior 0 indicates the end of the input, each set starts with an integer n, which represents the number of the collection string, and the next n rows are arranged in a non-descending length by n strings, each containing at least one but not more than 15 strings. Each string does not exceed 25 characters. Output for each collection, the first row outputs "Set-n", N starts at 1, and the next number of rows corresponds to the result of entering the rearrangement of each set, as shown in the sample. Sample input
7bopatjeankevinclaudewilliammarybeth6jimbenzoejoeyfrederickannabelle5johnbillfranstancece0
Sample output
Set-1bojeanclaudemarybethwilliamkevinpatset-2jimzoefrederickannabellejoeybenset-3johnfrancecestanbill
Hint Source

#include <iostream>
using namespace Std;
int main () {
int n,i,k,num=1;
String a[100],b[100];
while (cin>>n&&n!=0) {
k=0;
for (i=0;i<n;i++) {
cin>>a[i];
}
for (i=0;i<n;i=i+2) {
if (i==n-1) {
B[k]=a[i];
}else{
B[k]=a[i];
B[N-1-K]=A[I+1];
k=k+1;
}
}
cout<< "set-" <<num++<<endl;
for (i=0;i<n;i++) {
cout<<b[i]<<endl;
}
}


return 0;
}

1042: Clown Sort

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.