POJ 1035 Spell checker (串)

题目大意:

问你后面输入的串能不能通过  加减一个字符,或者替换一个字符变成字典中的串。

思路分析:

直接模拟替换加减的过程。

比较两个串的长度。要相差为1 的时候才能进行模拟。

模拟的过程就是进行一个个的匹配。

发现失配的次数小于等于 1就可以输出。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <map>
#define maxn 10005
using namespace std;

char str[maxn][20];
string tmp;
map <string,bool>mymap;

int main()
{
    while(scanf("%s",str[0])!=EOF)
    {
        mymap.clear();

        tmp=str[0];
        mymap[tmp]=true;

        int i=1;
        while(scanf("%s",str[i]) && str[i][0]!='#')
        {
            tmp=str[i];
            mymap[tmp]=true;
            i++;
        }

        char txt[20];
        while(scanf("%s",txt) && txt[0]!='#')
        {
            tmp=txt;

            if(mymap[tmp])printf("%s is correct\n",txt);
            else
            {
                printf("%s:",txt);
                int l=strlen(txt);
                for(int j=0;j<i;j++)
                {
                    int len=strlen(str[j]);
                    if(l+1==len)
                    {
                        int cnt=0;
                        int p=0,k=0;
                        while(p<l && k<len)
                        {
                            if(txt[p]==str[j][k]) p++,k++;
                            else {
                                cnt++;
                                k++;
                            }
                        }
                        if(cnt<=1 && p==l)printf(" %s",str[j]);
                    }
                    if(l==1+len)
                    {
                        int cnt=0;
                        int p=0,k=0;
                        while(p<len && k<l)
                        {
                            if(str[j][p]==txt[k])p++,k++;
                            else {
                                cnt++;
                                k++;
                            }
                        }
                        if(cnt<=1 && p==len)printf(" %s",str[j]);
                    }
                    if(l==len)
                    {
                        int cnt=0;
                        for(int k=0;k<len;k++)if(txt[k]!=str[j][k])cnt++;
                        if(cnt==1)printf(" %s",str[j]);
                    }
                }
                puts("");
            }
        }
    }
    return 0;
}

POJ 1035 Spell checker (串)

时间: 2024-08-04 06:44:54

POJ 1035 Spell checker (串)的相关文章

[ACM] POJ 1035 Spell checker (单词查找,删除替换增加任何一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

[ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word

POJ 1035 Spell checker

题目链接 http://poj.org/problem?id=1035 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 24142   Accepted: 8794 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the cor

poj 1035 Spell checker(暴力判断)

题目链接:http://poj.org/problem?id=1035 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their f

POJ 1035 Spell checker (模拟)

题目链接 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms. If the word is absent in

【POJ】1035 Spell checker

字典树. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <string> 7 using namespace std; 8 9 typedef struct Trie { 10 int in; 11 Trie *next[26]; 12 } Trie;

POJ训练计划1035_Spell checker(串处理/暴力)

3.算法综合实践--搜索引擎 上网搜索有关"搜索引擎"的相关资料,包括但不限于以下方面(至少要有2个方面):搜索引擎岗位要求.搜索引擎工作原理.搜索引 擎涉及到教材中哪些算法.搜索引擎的盈利模式.搜索引擎源码链接.国内外搜索引擎公司现状等. <1>搜索引擎指自动从因特网搜集信息,经过一定整理以后,提供给用户进行查询的系统.因特网上的信息浩瀚万千,而且毫无秩序,所有的信息像汪洋上的一个个小岛,网页链接是这些小岛之间纵横交错的桥梁,而搜索引擎,则为用户绘制一幅一目了然的信息地图

POJ 1035 Spell Check 字符串处理

被这样的题目忽悠了,一开始以为使用Trie会大大加速程序的,没想到,一不小心居然使用Trie会超时. 最后反复试验,加点优化,终于使用Trie是可以过的,不过时间大概难高于1500ms,一不小心就会超时. 看来这是一道专门卡Trie的题目,只好放弃不使用Trie了. 也得出点经验,如果字符串很多,如本题有1万个字符串的,那么还是不要使用Trie吧,否则遍历一次这样的Trie是十分耗时的,2s以上. 于是使用暴力搜索法了,这里的技巧是可以使用优化技术: 1 剪枝:这里直接分组搜索,分组是按照字符串

Spell checker POJ 1035 字符串

Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 Description You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given word