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 ...
随机推荐
- FindWindowEx
procedure CloseGameSver(); var H1, h2: HWND; begin H1 := FindWindow('TForm1', nil); h2 := FindWindow ...
- 通过ftp模拟网盘
package com.xiaomo.ftp.down_upload; import java.io.IOException; import java.util.ArrayList; import j ...
- iOS中的imageIO与image解码
ImageIO对外开放的对象有CGImageSourceRef.CGImageDestinationRef,不对外开放的对象有CGImageMetadataRef.CoreGraphics中经常与im ...
- asp.net分页控件库
AspNetPager分页控件 AspNetPager分页控件解决了分页中的很多问题,直接采用该控件进行分页处理,会将繁琐的分页工作变得简单化,下面是我如何使用AspNetPager控件进行分页处理的 ...
- Jsp中三种注释
在Jsp中有三种注释: 一.HTML注释 1.输出注释<!-- -->客户端查看源码时是可以看见的. 二.Java注释 1. //单行注释 2. /*多行注释*/ 三.JSP页注释 1 ...
- 8.LNMP环境的配置
LNMP环境的配置 参照文档:https://oneinstack.com/install/ 安装文件位置:/data/soft: ```yum -y install wget screen pyth ...
- hihocoder 第一周 最长回文字串
题目1 : 最长回文子串 时间限制:1000ms 单点时限:1000ms 内存限制:64MB 描述 小Hi和小Ho是一对好朋友,出生在信息化社会的他们对编程产生了莫大的兴趣,他们约定好互相帮助,在编程 ...
- jQuery多图上传Uploadify插件使用及传参详解
因为工作需要,这两天接触到了Uploadify插件,由于是第一次用,花了我近一天的时间.下面我把我在用这个插件过程详细的分享出来,也让自己巩固一下,也希望能帮助到你. 所需文件: jquery-1.8 ...
- Service解析
Service解析: 运行service有如下两种方式: StartService() 访问者退出,service仍然运行: BindService() 访问者与service绑定,访问者退出,ser ...
- Jquery Ajax调用aspx页面实例
目前,我会的几种asp.net界面与后台代码交互方式有几种: 1.webform+服务器控件交互: 2.webform+jquery+ajax+一般处理程序交互: 3.webform+jquery+a ...