Follows 400.c (Total 55 lines):

/* @JUDGE_ID:4461XX 400 C */
/* A */
#include<stdio.h>
#include<string.h>
char arr[100][100] ;
void my_swap( int i , int j )
{
	char arr1[100] ;
	int k ;
	strcpy( arr1 , arr[i] ) ;
	strcpy( arr[i] , arr[j] ) ;
	strcpy( arr[j] , arr1 ) ;
}
void sort( int i , int j )
{
	int k , len , changed=0 ;
	if( strlen( arr[i] ) < strlen( arr[j] ) ) len = strlen( arr[i] ) ;
	else len = strlen( arr[j] ) ;
	for( k=0 ; k<len ; k++ ){
		if( arr[i][k] < arr[j][k] ){
			changed = 1 ;
			break ;
		}
		if( arr[i][k] > arr[j][k] ){
			my_swap( i , j ) ;
			changed = 1 ;
			break ;
		}
	}
	if( strlen( arr[i] ) > strlen( arr[j] ) && !changed ) my_swap( i , j ) ;
}
void main( void )
{
	int n , i , j , column , biglen , space , times , dive ;
/*	freopen( "C:\\windows\\desktop\\400.txt" , "r" , stdin ) ;
	freopen( "C:\\windows\\desktop\\400out.txt" , "w" , stdout ) ;*/
	while( scanf( "%d\n" , &n )==1 ){
		biglen = 0 ;
		for( i=0 ; i<n ; i++ ){
			gets( arr[i] ) ;
			if( strlen( arr[i] ) > biglen ) biglen = strlen( arr[i] ) ;
		}
		for( i=0 ; i<n-1 ; i++ )
			for( j=i+1 ; j<n ; j++ ) sort( i , j ) ;
		column = 1 + ( 60 - biglen ) / ( biglen + 2 ) ;
		puts( "------------------------------------------------------------" ) ;
		if( n%column == 0 ) dive = n / column ;
		else dive = 1 + n / column ;
		for( j=0 , times=1 ; times<=n ; j++ , putchar( '\n' ) )
			for( i=j ; i<n ; i+=dive , times++ ){
				printf( "%s" , arr[i] ) ;
				for( space=0 ; space<biglen+2-strlen( arr[i] ) ; space++ ) printf( " " ) ;
			}
	}
}

Back to statistics
Ya-Lin Huang (C)
huangyl@gmail.com