C語言源碼: [cpp] #include<stdio.h> #include<string.h> #include<stdlib.h> typedef struct num { char s[1010]; int len; }num; int cmp(const void *a,const void *b) { struct num *aa=(num *)a; struct num *bb=(num *)b; return strcmp(aa->s,bb->s); } int main() { num a[110]; int n,i,length,j; char p[1010]; while(scanf("%d",&n)!=EOF) { for(i=0;i<n;i++) { getchar(); scanf("%s",p); length=(int)strlen(p); a[i].len=1010-length-2; for(j=0;j<1009;j++) { if(j<=a[i].len) a[i].s[j]='0'; else a[i].s[j]=p[j-a[i].len-1]; } a[i].s[j]='\0'; } qsort(a,n,sizeof(a[0]),cmp); for(i=0;i<n;i++) { for(j=a[i].len+1;j<1009;j++) printf("%c",a[i].s[j]); printf("\n"); } } }