Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什么会RE啊?找了好久了,哪个大牛帮我看看啊!(附代码)In Reply To:为什么会RE啊?找了好久了,哪个大牛帮我看看啊!(附代码) Posted by:hezhenbin at 2008-10-17 10:52:25 我的也RE得莫名其妙。。。。。哪位高手帮我看看 /* Author: sgxiao Title: 1589 -- Unix ls LANG: C Date : Sun Dec 7 00:35:23 CST 2008 */ #include<stdio.h> #include<stdlib.h> #include<string.h> #define CONVERT(a) *((char **)a) char filenames[105][65]; char* ptr_file[105]; int length[105]; int compare(const void *a,const void *b){ return strcmp( CONVERT(a), CONVERT(b) ); } int main(void) { int i, j, k; int n; int longest_length; int row, column; while( scanf("%d", &n) != EOF ) { longest_length = 0; for(i = 0; i < n; i++) { scanf("%s", filenames[i]); length[i] = strlen(filenames[i]); ptr_file[i] = filenames[i]; if( longest_length < length[i] ) longest_length = length[i]; } /* sort the filenames */ qsort(ptr_file, n, sizeof(char *), compare); column = 60 / (longest_length + 2); row = ((n % column) ? (n / column + 1) : (n / column)); printf("------------------------------------------------------------\n"); for(i = 0; i < row; i++) { for(j = 0; j < column; j++) { if( ptr_file[i + j * row] != NULL ) { printf("%s", ptr_file[i + j * row]); /* need more blank */ if( j != column - 1 && (i + j * row) < n - column + 1) { for(k = 0; k < longest_length - strlen(ptr_file[i + j * row]); k++) { printf(" "); } printf(" "); } } } printf("\n"); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator