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:Romantic0815 at 2012-03-15 16:34:35 > #include <iostream> > #include <cstring> > #include <cstdio> > #include <string.h> > #include <string> > #include <algorithm> > using namespace std; > > struct node { > char c[20]; > int seq; > }joint[20][2010]; > char in[20]; > int countf[20],num,ans; > struct nodeForAnswer{ > int cf; > char ca[20]; > }reserve[2010]; > > bool findTheSame(int n,char *in) > { > int i;int j = ans;int add; > for(i = 0;i < countf[n];i++) > { > add = 0; > if(!strcmp(in,joint[n][i].c)) > { > strcpy(reserve[ans].ca,joint[n][i].c);reserve[ans].cf = joint[n][i].seq;ans++; > return true; > } > for(int k = 0;k < n;k++) > if(in[k] != joint[n][i].c[k]) > add++; > if(add == 1){ > strcpy(reserve[j].ca,joint[n][i].c); > reserve[j].cf = joint[n][i].seq;j++; > } > } > ans = j; > return false; > } > > void findSubOne(int n,char *in) > { > int i,k,j;int nut = 0; > for(i = 0;i < countf[n-1];i++) > { > nut = 0; > for(k = 0,j = 0;k < n;) > { > if(in[k] != joint[n-1][i].c[j])nut++,k++; > else k++,j++; > if(nut >= 2)break; > } > if(nut >= 2)continue; > strcpy(reserve[ans].ca,joint[n-1][i].c); > reserve[ans].cf = joint[n-1][i].seq; > ans++; > } > } > > void findAddOne(int n,char *in) > { > int i,k,j;int nut; > for(i = 0;i < countf[n+1];i++) > { > nut = 0; > for(k = 0,j = 0;k < n;) > { > if(in[k] != joint[n+1][i].c[j])nut++,j++; > else j++,k++; > if(nut >= 2)break; > } > if(nut >= 2)continue; > strcpy(reserve[ans].ca,joint[n+1][i].c); > reserve[ans].cf = joint[n+1][i].seq; > ans++; > } > } > > int cmp(const void* e,const void* f) > { > struct nodeForAnswer *ee = (nodeForAnswer*)e; > struct nodeForAnswer *ff = (nodeForAnswer*)f; > return (ee->cf > ff->cf); > } > > int main() > { > int i;num = 0; > memset(countf,0,sizeof(countf)); > memset(joint,0,sizeof(joint)); > while(scanf("%s",in) && strcmp(in,"#") != 0) > { > i = strlen(in); > strcpy(joint[i][countf[i]].c,in); > joint[i][countf[i]].seq = num; > num++;countf[i]++; > } > while(scanf("%s",in) && strcmp(in,"#") != 0) > { > i = strlen(in);ans = 0; > if(findTheSame(i,in)){ > printf("%s is correct\n",in); > } > else { > findSubOne(i,in); > findAddOne(i,in); > qsort(reserve,ans,sizeof(reserve[0]),cmp); > printf("%s:",in); > for(i = 0;i < ans;i++) > printf(" %s",reserve[i].ca); > 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