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 |
可能是我题目没读懂,请教几组输入的结果26 a b c d e f g h i j k l m n o p q r s t u v w x y z 我的程序是 ------------------------------------------------------------ a c e g i k m n o p q r s t u v w x y z b d f h j l 不晓得错在哪里了,反正wa的有些郁闷了,附带源代码 #include<stdio.h> #include<string.h> #include<stdlib.h> struct file{ char name[99]; int len; }; int cmp(const void * a,const void * b){ return strcmp(((file*)a)->name,((file*)b)->name); } int main(){ int fileNum,maxLen,i,rows,cols,j,k,map[100][22]; file files[200]; char bu[99]; while(gets(bu)){ sscanf(bu,"%d",&fileNum); maxLen=0; for(i=0;i<fileNum;i++){ gets(files[i].name); files[i].len=strlen(files[i].name); if(files[i].len>maxLen)maxLen=files[i].len; } cols=62/(maxLen+2); rows=fileNum/cols+(fileNum%cols?1:0); cols++; rows++; for(i=0;i<rows;i++)for(j=0;j<cols;j++)map[i][j]=0; cols--; rows--; for(k=i=0;i<rows;i++)for(j=0;j<cols;j++){ map[i][j]=1; k++; if(k>=fileNum)goto end; } end: qsort(files,fileNum,sizeof(files[0]),cmp); k=1; for(i=0;i<cols;i++)for(j=0;j<rows;j++){ if(map[j][i]){ map[j][i]=k++; }else{ break; } } printf("------------------------------------------------------------\n"); for(i=0;i<rows;i++){ for(j=0;j<cols;j++){ if(map[i][j]){ printf("%s",files[map[i][j]-1].name); if(map[i][j+1]){ for(k=files[map[i][j]-1].len;k<maxLen+2;k++)printf(" "); }else{ 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