• POJ 1035 Spell checker


    按照 CSGrandeur 大牛的给出的方法做的;

    暴力即可;

    判断是否可以添加一个 字符得到时,有点小技巧,具体见代码;

    # include <stdio.h>
    # include <string.h>
    
    # define WL 17
    
    int n;
    char dic[10005][WL], word[WL];
    
    char exist(char *buf)
    {
        int i;
    
        for (i = 0; i < n; ++i)
        {
            if (strcmp(dic[i], word) == 0) return 1;
        }
    
        return 0;
    }
    
    char replace(char *x, char *y)
    {
        int i, lenx, leny, cnt;
    
        lenx = strlen(x), leny = strlen(y);
        if (lenx != leny) return 0;
        for (cnt = 0, i = 0; i < lenx; ++i)
        {
            if (x[i] != y[i]) ++cnt;
            if (cnt > 1) return 0;
        }
        return 1;
    }
    
    char add(char *x, char *y)
    {
        int i, j, lenx, leny, cnt;
    
        lenx = strlen(x), leny = strlen(y);
        if (leny != lenx+1) return 0;
        for (cnt = 0, i = 0, j = 0; i < leny; ++i, ++j)
        {
            if (x[i] != y[j]) ++cnt, --i;
            if (cnt > 1) return 0;
        }
        return 1;
    }
    
    void find(char *buf)
    {
        int i;
    
        printf(":");
        for (i = 0; i < n; ++i)
        {
            if (replace(dic[i], buf) || add(buf, dic[i]) || add(dic[i], buf))
                printf(" %s", dic[i]);
        }
    }
    
    int main()
    {
        for (n = 0; scanf("%s", dic[n]), dic[n][0] != '#'; ++n) ;
        for ( ; scanf("%s", word), word[0] != '#'; )
        {
            printf("%s", word);
            if (exist(word)) printf(" is correct");
            else find(word);
            putchar('\n');
        }
    
        return 0;
    }

    //

  • 相关阅读:
    Javascript闭包的一些研究
    pytorchvision安装问题
    CUDA 基础
    语音识别入门推荐文献【转】
    【e2e】espnet框架安装问题集锦
    维特比算法与beam search
    kaldi识别问题集锦
    语音识别-重要开源数据
    git提交失败总结
    钟南山病后反思: 寿命长短, 不取决于衰老和疾病【转】
  • 原文地址:https://www.cnblogs.com/JMDWQ/p/2582718.html
Copyright © 2020-2023  润新知