PersonalCorpus 版 (精华区)
/* THANKS TO PAWMS !!! */
40951 2002-10-12 12:45:35 Accepted
1324 C++ 00:00.01 392K Big Guava
void printl(char *s,int l)
{
printf("%s",s);
if (l>0) for (int i=strlen(s);i<l;i++) printf(" ");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("c:\\0acm\\uva\\input400.txt","r",stdin);
freopen("c:\\0acm\\uva\\output400_4.txt","w",stdout);
#endif
char s[100][100],t[100];
int i,j,k,n,maxl,c,m,a,b;
int fin;
while (scanf("%d\n",&n)==1) {
printf("------------------------------------------------------------\n")
;
maxl=0;
for (i=0;i<n;i++) {
gets(s[i]);
for (j=strlen(s[i])-1;j>=0;j--)
if (isalnum(s[i][j]) || s[i][j]=='.' ||
s[i][j]=='_' ||
s[i][j]=='-') {
s[i][j+1]=0;
break;
}
j=strlen(s[i]); if (j>maxl) maxl=j;
}
for (i=0;i<n-1;i++) {
for (j=i+1;j<n;j++) if (strcmp(s[i],s[j])>0) {
strcpy(t,s[j]);
strcpy(s[j],s[i]);
strcpy(s[i],t);
}
}
c=62/(maxl+2); a=(n+c-1)/c; b=a*c-n;
for (i=0;i<a-b;i++) {
for (j=0;j<c-1;j++) printl(s[a*j+i],maxl+2);
j=c-1; printl(s[a*j+i],0);
printf("\n");
}
for (i=a-b;i<a;i++) {
for (j=0;j<c-2;j++) printl(s[a*j+i],maxl+2);
j=c-2; printl(s[a*j+i],0);
printf("\n");
}
}
}
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:2.253毫秒