标签:des style blog io color ar os sp for
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
1 #include <stdio.h> 2 #include <string.h> 3 4 int main(){ 5 char name[20][30]; 6 char temp[20][30]; 7 char compare[30]; 8 int id[20]; 9 int int_temp; 10 int n; 11 int i; 12 int j; 13 int k; 14 int time; 15 int length1; 16 int length2; 17 18 time=1; 19 20 while(1){ 21 scanf("%d",&n); 22 23 if(n==0) 24 break; 25 26 for(i=0;i<n;i++) 27 id[i]=i; 28 29 for(i=0;i<n;i++){ 30 scanf("%s",&name[i]); 31 } 32 33 for(i=0;i<n-1;i++){ 34 for(j=i+1;j<n;j++){ //主要是参与比较的是长度,当两个字符串长度一样时值却可能不一样,所以要进行标记位置 35 length1=strlen(name[i]); 36 length2=strlen(name[j]); 37 38 if(length1>length2 || (length1==length2 && id[i]>id[j])){ 39 strcpy(compare,name[i]); 40 strcpy(name[i],name[j]); 41 strcpy(name[j],compare); 42 43 int_temp=id[i]; 44 id[i]=id[j]; 45 id[j]=int_temp; 46 } 47 } 48 } 49 50 j=0; 51 k=n-1; 52 for(i=0;i<n;i++){ 53 if((i+1)%2==1){ 54 strcpy(temp[j],name[i]); 55 j++; 56 } 57 58 else{ 59 strcpy(temp[k],name[i]); 60 k--; 61 } 62 } 63 64 printf("SET %d\n",time); 65 time++; 66 67 for(i=0;i<n;i++) 68 printf("%s\n",temp[i]); 69 } 70 return 0; 71 }
标签:des style blog io color ar os sp for
原文地址:http://www.cnblogs.com/zqxLonely/p/4099742.html