POJ 1035 Spell checker 简单字符串匹配
在输入的单词中删除或替换或插入一个字符,看是否在字典中。直接暴力,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 简单字符串匹配的更多相关文章
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18693 Accepted: 6844 De ...
- POJ 1035 Spell checker (模拟)
题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- poj 1035 Spell checker(水题)
题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...
- poj 1035 Spell checker(hash)
题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...
- POJ 1035 Spell checker(串)
题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...
- 【POJ】1035 Spell checker
字典树. #include <iostream> #include <cstdio> #include <cstring> #include <cstdlib ...
随机推荐
- 对Jsp提交input标签空格和回车的处理
今天做增加的时候发现一个问题,在js中去掉空格的时候如果这么写 var stage_name = document.getElementById("stage_name").val ...
- 理解URI和URL
1)定义: URI: Uniform Resource Identifier,通用资源标识符 ---是一个用于标识某一互联网资源名称的字符串(by 维基百科) URL:Uniform Resource ...
- Java immutable class
可变类:类的实例创立之后,还可以修改这个实例的内容. 比如创建一个3*3的矩阵,如果设立了set function,在main中可以用set更改对应位置元素的大小. 不可变类:就是类的实例一旦被建立, ...
- hibernate篇章三-- hibernate配置文件hibernate.cfg.xml的详细解释
<!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> <?xml version='1.0' ...
- Android开发之Menu组件
菜单Menu大致分为三种类型:选项菜单(OptionsMenu),上下文菜单(ContextMenu),子菜单(SubMenu). 1.选项菜单 在一个Activity界面中点击手机Menu键,在屏幕 ...
- CentOS 6.4安装OpenOffice
终端依次输入: (1)sudo yum install openoffice.org-writer (2) sudo yum install openoffice.org-calc (3) sudo ...
- word公式图片显示不全的问题
最近处理文档遇到比较棘手的问题,就是单行显示的公式和图片都显示不全,高度撑不起来,会被其他行的内容遮挡. 图片估计是对齐方式照成的,公式调了很久也没有办法.最后找了一个临时折衷的办法: 插入表格,然后 ...
- 如何重写EF DBContext 获取链接字符串的方法
public partial class byvarDBFirst: DbContext { //使用自定义连接串 private static string GetEFConnctionString ...
- 03_MySQL中文乱码处理_01_MySQl数据库字符集知识
[MySql数据库常见字符集介绍] 在互联网环境中,使用MySql时常用的字符集有: [如何选择合适的字符集] 1.如果处理各种各样的文字,发布到不同语言的国家地区,应选Unicode字符集,对MyS ...
- STL unique使用问题
string strs[] = {"one","one","two","three","three" ...