#include "stdio.h" struct thedic{ char wordname[17]; int thelen; }thedic_p[10010]; int i =0; int p =0; int x=0; int correct =0; int j,count,len,mywordlen,totalnumber; char myword[17]; char * tempword; char* tempmyword; char wordtopass[17]; //Replace one character void replace(const char * wordpro,const char * dicword){ int count =0; tempword = dicword; tempmyword = wordpro; for(j=0;j<strlen(tempword);j++){ if(tempmyword[j] != tempword[j])count++; if(count > 1)return; } printf(" %s",tempword); } //Add one character to myword void add(const char * wordpro,const char *dicword){ tempword = dicword; tempmyword = wordpro; for(j=0;j<=strlen(tempword);j++){ if(tempmyword[j] != tempword[j]){ len = strlen(tempmyword); while(len-- > j){ tempmyword[len+1]=tempmyword[len]; } tempmyword[j] = tempword[j]; if(!strcmp(tempmyword,tempword)){ printf(" %s",tempword); } return; } } return; } //Delete one character from myword void deleteone(const char * wordpro,const char * dicword){ tempword = dicword; tempmyword = wordpro; for(j=0;j<strlen(tempmyword);j++){ if(tempmyword[j] != tempword[j]){ len = strlen(tempmyword); if(j <(len-1)){ while(j++ < (len-1)){ tempmyword[j-1]=tempmyword[j]; tempmyword[j] =''; } } else if(j== (len-1)){ tempmyword[j] =' '; } if(!strcmp(tempmyword,tempword)){ printf(" %s",tempword); } return; } } return; } int main(void) { #ifndef ONLINE_JUDGE freopen("in.txt","r",stdin); #else #endif while(scanf("%s",thedic_p[i++].wordname)){ if(!strcmp(thedic_p[i-1].wordname,"#")){ totalnumber = i-1; break; } thedic_p[i-1].thelen= strlen(thedic_p[i-1].wordname); } for(;;){ for(i=0;i<17;i++){ myword[i]=' '; wordtopass[i]=' '; } correct=0; scanf("%s",myword); if(!strcmp(myword,"#"))break; mywordlen=strlen(myword); for(p=0;p<totalnumber;p++){ //printf("") if(!strcmp(myword,thedic_p[p].wordname)){ printf("%s is correctn",myword); correct=1; break; } } if(correct != 1){ printf("%s:",myword); for(p=0;p<totalnumber;p++){ strcpy(wordtopass,myword); if(abs(mywordlen-thedic_p[p].thelen)>1)continue; if(mywordlen==thedic_p[p].thelen) replace(wordtopass,thedic_p[p].wordname); if(mywordlen > thedic_p[p].thelen) deleteone(wordtopass,thedic_p[p].wordname); else add(wordtopass,thedic_p[p].wordname); } printf("n"); } } }
POJ1035
最新推荐文章于 2020-03-11 22:31:27 发布