POJ1035

#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");
     }
     }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值