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:牛人们帮帮看看,我测试几组数据都没有问题,提交总说答案错误,第一次来,对与测试系统不太清楚In Reply To:牛人们帮帮看看,我测试几组数据都没有问题,提交总说答案错误,第一次来,对与测试系统不太清楚 Posted by:hubenlong at 2010-05-15 15:45:58 > #include <stdio.h> > #include <stdlib.h> > > typedef struct inode{ > int UnsortNum; > char *ptr; > inode *next; > }Inode,*pInode; > > int CountUnsortNum(char buffer[],int m) > { > int i=0,j=0; > int sum=0; > for(i=0;i<m-1;i++) > for(j=i+1;j<m;j++) > if(buffer[i]>buffer[j]) > ++sum; > return sum; > } > > > int main() > { > int m,n,i,j; > pInode plink; > //char c; > char **buffer; > scanf("%d %d",&m,&n); > buffer=(char**)malloc(n*sizeof(char*)); > for(i=0;i<n;i++) > buffer[i]=(char*)malloc((m+1)*sizeof(char)); > > if(!buffer) > exit(-1); > char c; > > fflush(stdin); > for(i=0;i<n;i++){ > for(j=0;j<m;j++){ > c=getchar(); > //printf("%c\n",c); > while(c=='\n'||c=='\r'||c=='\t'||c==' ') > { > if(j!=0) > { > printf("i is %d,j is %d\n",i,j); > exit(-1); > } > c=getchar(); > } > // if((c!='A')&&(c!='T')&&(c!='G')&&(c!='C')) > // exit(-1); > buffer[i][j]=c; > } > buffer[i][m]='\0'; > } > > plink=(pInode)malloc(sizeof(Inode)); > pInode p,ptemp; > p=plink; > p->next=NULL; > > for(i=0;i<n;i++){ > if(!(ptemp=(pInode)malloc(sizeof(Inode)))) > exit(-1); > ptemp->ptr=buffer[i]; > ptemp->UnsortNum=CountUnsortNum(buffer[i],m); > > ptemp->next=NULL; > p->next=ptemp; > p=p->next; > } > int min=0; > pInode premin; > > while(plink->next){ > premin=plink; > min=plink->next->UnsortNum; > for(p=plink;p->next!=NULL;p=p->next) > { > if(p->next->UnsortNum<min){ > premin=p; > min=p->next->UnsortNum; > } > } > printf("%s\n",premin->next->ptr); > p=premin->next; > premin->next=p->next; > free(p); > p=NULL; > } > free(plink); > plink=NULL; > for(i=0;i<n;i++){ > free(buffer[i]); > buffer[i]=NULL; > } > free(buffer); > buffer=NULL; > > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator