在输入的单词中删除或替换或插入一个字符,看是否在字典中。直接暴力,172ms。。

 #include <stdio.h>
#include <string.h>
int len[];
char dic[][], s[]; bool del(char s1[], char s2[])
{
bool isdel = ;
for(int i = , j = ; s1[i] && s2[j]; i++, j++)
{
if(s1[i] != s2[j])
{
if(isdel)
return ;
j--;
isdel = ;
}
}
return ;
} bool rep(char s1[], char s2[])
{
bool isrep = ;
for(int i = , j = ; s1[i] && s2[j]; i++, j++)
{
if(s1[i] != s2[j])
{
if(isrep)
return ;
isrep = ;
}
}
return ;
} bool ins(char s1[], char s2[])
{
bool isins = ;
for(int i = , j = ; s1[i] && s2[j]; i++, j++)
{
if(s1[i] != s2[j])
{
if(isins)
return ;
i--;
isins = ;
}
}
return ;
} int main()
{
int cnt = ;
while(scanf("%s", dic[cnt]) != EOF)
{
if(dic[cnt][] == '#')break;
len[cnt] = strlen(dic[cnt++]);
}
while(scanf("%s", s) != EOF)
{
if(s[] == '#')break;
bool ok = ;
for(int i = ; i < cnt; i++)
{
if(strcmp(s, dic[i]) == )
{
ok = ;
printf("%s is correct", s);
}
}
if(!ok)
{
printf("%s:", s);
int len_s = strlen(s);
for(int i = ; i < cnt; i++)
{
if(len_s - len[i] == && del(s, dic[i]))
printf(" %s", dic[i]);
if(len_s - len[i] == && rep(s, dic[i]))
printf(" %s", dic[i]);
if(len_s - len[i] == - && ins(s, dic[i]))
printf(" %s", dic[i]);
}
}
printf("\n");
}
return ;
}

POJ 1035 Spell checker 简单字符串匹配的更多相关文章

  1. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  2. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

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

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 De ...

  4. POJ 1035 Spell checker (模拟)

    题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...

  5. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  6. poj 1035 Spell checker(水题)

    题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...

  7. poj 1035 Spell checker(hash)

    题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...

  8. POJ 1035 Spell checker(串)

    题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...

  9. 【POJ】1035 Spell checker

    字典树. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib ...

随机推荐

  1. 【Linq递归查找系列】

    Linq递归查找: public IEnumerable<MenuInfo> GetTree(int id, IEnumerable<MenuInfo> lst) { var ...

  2. 谋哥:App排行榜的秘密

    App在改变世界,改变人们的生活.       如今购物大家都用淘宝.京东,吃饭你会用饭否,看天气预报你用墨迹天气,看视频用优酷.K歌你用唱吧,聊天联系你用微信,看新闻你用今日头条等等.你的生活由你自 ...

  3. 标准I/O库之打开和关闭流

    下列三个函数打开一个标准I/O流. #include <stdio.h> FILE *fopen( const char *restrict pathname, const char *r ...

  4. flex学习网站地址

    http://hacker47.iteye.com/blog/213887 http://www.cuplayer.com/player/PlayerCode/Flex/ http://bbs.9ri ...

  5. 谓词(NSPredicate)

    OC中的谓词操作是针对于数组类型的,他就好比数据库中的查询操作,数据源就是数组,这样的好处是我们不需要编写很多代码就可以去操作数组,同时也起到过滤的作用,我们可以编写简单的谓词语句,就可以从数组中过滤 ...

  6. Java内存模型浅析

    JVM在执行java程序时会将它所管理的内存划分成若干个不同的数据区域.如图所示: 其中方法区和堆是所有线程共享的数据区,其他区域则是线程隔离的数据区. 这些区域的功能各有不同: 程序计数器:可以理解 ...

  7. 【S】【S】【S】一大波前端干货整合(一)

      前端交流站点 大前端       http://www.daqianduan.com/ V2EX       http://www.v2ex.com/ W3cplus    http://www. ...

  8. C#的语句

    什么是语句?语句可以是以分号结尾的单行代码,或者是语句块中的一系列单行语句.语句块括在括号 {} 中,并且可以包含嵌套块. 1,语句的类型 (1)声明语句 声明语句主要是引入新的变量和常量.变量的声明 ...

  9. 序列化之Parcelable

    序列化主要是用来传递类的信息,一般java有提供serializable类,这个类用的较多,不过在android上面似乎效率不高,于是google开发了针对性的优化的接口,parcelable接口. ...

  10. AJAX与servlet的信息交互

    <%@ page language="java" import="java.util.*" pageEncoding="gb2312" ...