• poj1035 Spell checker


    这题目比较简单,把思路搞清楚就可以啦。

    #include <stdio.h>
    #include <string.h>
    char words[10000+10][20];
    
    int init(){
        int cnt=0;
        while(~scanf("%s",words[cnt])){
            if(strcmp("#",words[cnt])==0) return cnt;
            cnt++;
        }
    }
    int judge(char a[],char b[]){
        int success;
        int la=strlen(a);
        int lb=strlen(b);
        int i,j,k;
        int cnt=0;
        if(la==lb){
            for(i=0;i<la;++i)
                if(a[i]!=b[i])
                    cnt++;
            if(cnt==1) return 1;
        }
    
    
        if(la==lb+1)
        for(i=0;i<la;++i){
            success=1;
            for(j=0,k=0;j<la&&k<lb;){
                if(j==i){
                    j++;continue;
                }
                if(a[j]!=b[k]){
                    success=0;
                }
                j++;k++;
            }
            if(success==1) return 1;
        }
        if(la+1==lb)
        for(i=0;i<lb;++i){
            success=1;
            for(j=0,k=0;j<la&&k<lb;){
                if(k==i){
                    k++;continue;
                }
                if(a[j]!=b[k]){
                    success=0;
                }
                j++;k++;
            }
            if(success==1) return 1;
        }
        return 0;
    }
    
    void done(int cnt){
        char tmp[20];
        int i;
        int success;
        while(~scanf("%s",tmp)){
            if(strcmp(tmp,"#")==0)
                return;
            success=0;
            for(i=0;i<cnt;++i){
                if(strcmp(words[i],tmp)==0){
                    printf("%s is correct
    ",tmp);
                    success=1;
                    break;
                }
            }
            if(success==1) 
                continue;
            printf("%s:",tmp);
            for(i=0;i<cnt;++i){
                if( judge(words[i],tmp)==1){
                    printf(" %s",words[i]);
                }
            }
            printf("
    ");
        }
        return ;
    }
    int main(){
        done(init());
        return 0;
    }
  • 相关阅读:
    我的期末可以加分项
    冲刺
    公司授课管理系统
    挑战赛题终于完成
    Java web 学习
    Java web 学习
    Javaweb 学习
    Base64加密
    选课系统
    Educational Codeforces Round 62题解
  • 原文地址:https://www.cnblogs.com/symons1992/p/3505272.html
Copyright © 2020-2023  润新知