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 |
高手能不能给些测试数据?不胜感激!大牛们能不能给些测试数据?不胜感激! #include<stdio.h> #include<stdlib.h> #include<string.h> typedef struct words { char word[16]; struct words* next; int num; }Words; Words* wordshead[15]; Words* wordstail[15]; Words* insertword(Words* head,Words* tail,Words* word); int resolve(Words*,Words*,Words*,Words*,int,char*); int main() { int num=0; char temp[16]; int len=0,i=0,j=0; for(i=0;i<15;i++) { wordshead[i]=(Words*)malloc(sizeof(Words)); wordstail[i]=wordshead[i]; memset(wordshead[i]->word,'\0',16); wordshead[i]->next=NULL; } while((scanf("%s",temp)==1)&&temp[0]!='#') { len=strlen(temp); //wordstail[len-1]=insertword(wordshead[len-1],wordstail[len-1],temp); wordstail[len-1]->next=(Words*)malloc(sizeof(Words)); wordstail[len-1]=wordstail[len-1]->next; wordstail[len-1]->next=NULL; wordstail[len-1]->num=num++; strcpy(wordstail[len-1]->word,temp); } while(scanf("%s",temp)==1&&temp[0]!='#') { len=strlen(temp); if(len==1) { resolve(NULL,NULL,wordshead[1]->next,wordstail[1]->next,len-1,temp); } else if(len==15) { resolve(wordshead[13]->next,wordstail[13]->next,NULL,NULL,len-1,temp); } else { resolve(wordshead[len-2]->next,wordstail[len-2]->next,wordshead[len]->next,wordstail[len]->next,len-1,temp); } } return 0; } Words* insertword(Words* head,Words* tail,Words* okname) { Words* temp=head; while(head&&head->num<okname->num) { temp=head; head=head->next; } if(!head) { tail->next=(Words*)malloc(sizeof(Words)); tail=tail->next; tail->next=NULL; strcpy(tail->word,okname->word); tail->num=okname->num; } else { temp->next=(Words*)malloc(sizeof(Words)); temp=temp->next; strcpy(temp->word,okname->word); temp->num=okname->num; temp->next=head; } return tail; } int resolve(Words* previoushead,Words* previoustail,Words* nexthead,Words* nexttail,int len,char* name) { Words* result=(Words*)malloc(sizeof(Words)); Words* resulttail=result; Words* tempresult; int i=0; int templen=0; char tempname[16]; char tiqu[16]; Words* temp=wordshead[len]->next; memset(result->word,'\0',16); result->next=NULL; result->num=-1; for(temp;temp;temp=temp->next) { if(!strcmp(temp->word,name)) { printf("%s is correct\n",name); return 0; } } printf("%s:",name); for(i=0;i<strlen(name);i++) { memset(tiqu,'\0',16); memset(tempname,'\0',16); strcpy(tempname,name); tempname[i]='\0'; strcpy(tiqu,tempname); strcat(tiqu,tempname+i+1); for(temp=previoushead;temp;temp=temp->next) { if(!strcmp(tiqu,temp->word)) { //printf(" %s",temp->word); resulttail=insertword(result,resulttail,temp); } } } for(temp=wordshead[len]->next;temp;temp=temp->next) { int flag=0; for(i=0;i<strlen(name);i++) { if(name[i]!=temp->word[i]) { if((++flag)==2) break; } } if(flag!=2) { // printf(" %s",temp->word) resulttail=insertword(result,resulttail,temp); } } for(temp=nexthead;temp;temp=temp->next) { for(i=0;i<strlen(temp->word);i++) { memset(tiqu,'\0',16); memset(tempname,'\0',16); strcpy(tempname,temp->word); tempname[i]='\0'; strcpy(tiqu,tempname); strcat(tiqu,tempname+i+1); if(!strcmp(tiqu,name)) { //printf(" %s",temp->word); resulttail=insertword(result,resulttail,temp); } } } for(tempresult=result->next;tempresult;tempresult=tempresult->next) { printf(" %s",tempresult->word); } while(result) { tempresult=result; result=result->next; free(tempresult); } printf("\n"); } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator