zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    %2d
    将块中的文字设置成属性,即实现块中文字可拖动的功能
    获得块参照的插入点方法
    排序
    将几个实体对象变成一个块
    对克隆实体的类型转换
    对实体的克隆
    递归-顺序输出任意正整数各位
    递归-汉诺塔
    递归-最大公约数
  • 原文地址:https://www.cnblogs.com/symons1992/p/3505272.html
Copyright © 2011-2022 走看看