Symmetric Order C language ZOJ2172

Source: Internet
Author: User

In the your job at Albatross Circus Management (yes, it's run by a bunch of clowns) and you have just finished writing a program Whose output is a list of names in nondescending order by length (so, each name was at least as long as the one Precedi ng it). However, your boss does not like the the-the-the-the-the--the output looks, and instead wants the output to appear more symmetric, with the Shorter strings at the top and bottom and the longer strings in the middle. The names belongs on opposite ends of the list, and the first name in the pair are always in the Top part of the list. In the first example set below, Bo and Pat is the first pair, Jean and Kevin the second pair, etc.

Input

The input consists of one or more sets of strings, followed to a final line containing only the value 0. Each set starts with a line containing an integer, n, which are the number of strings in the set, followed by N strings, one per line, sorted in nondescending order by length. None of the strings contain spaces.  There is at least one and no more than strings per set. Each string is at the most characters long.

Output

For each input set print "Set n" on a line, where n starts at 1, followed by the output set as shown in the sample output.

Example Input: Example output:
7
Bo
Pat
Jean
Kevin
Claude
William
Marybeth
6
Jim
Ben
Zoe
Joey
Frederick
Annabelle
5
John
Bill
Fran
Stan
Cece
0
SET 1
Bo
Jean
Claude
Marybeth
William
Kevin
Pat
SET 2
Jim
Zoe
Frederick
Annabelle
Joey
Ben
SET 3
John
Fran
Cece
Stan
Bill

This problem can be entered by the name is an odd number or even a number of separate processing, note that after reading the number of people to remove the line break.

1#include <stdio.h>2#include <malloc.h>3#include <string.h>4 5 intMainvoid){6     intN//Number of names7     intI=1;//Set Number8     intJ//for Loop9     Char**name,t;//A pointer to a two-dimensional array of namesTen      while(SCANF ("%d", &n) = =1){ Onescanf"%c", &t);//read in line breaks A         if(n==0) Break; -         Else{ -Name= (Char**)malloc(nsizeof(Char*)); the              for(j=0; j<n;j++) name[j]= (Char*)malloc( -*sizeof(Char)); -              for(j=0; j<n;j++) gets (Name[j]); -printf"SET%d\n", i++);//set number plus one -             //individually output by odd and even +             if(n%2==0){ -                  for(j=0; j<n;j+=2) puts (name[j]); +                  for(j=n-1;j>0; j-=2) puts (name[j]); A}Else{ at                  for(j=0; j<n;j+=2) puts (name[j]); -                  for(j=n-2;j>0; j-=2) puts (name[j]); -             } -         } -          for(j=0; j<n;j++) Free(Name[j]); -          Free(name); in     } -     return 0; to}
View Code

Symmetric Order C language ZOJ2172

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.