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 ...
随机推荐
- Installing the PHP/MongoDB extension on Mac OSX 10.8
Installing PHP/MongoDB extension is a two steps task on OSX: Install the autoconf tool required for ...
- [React] React Fundamentals: Owner Ownee Relationship
The owner-ownee relationship is used to designate a parent-child relationship with React components ...
- OPTIMIZE TABLE
INNODB 不支持 mysql> OPTIMIZE TABLE t; +--------+----------+----------+----------------------------- ...
- 定制操作(传递函数或lambda表达式)
很多算法都会比较输入序列中的元素.默认情况下,这类算法使用元素类型的<或==运算符完成比较.标准库还为这些算法定义了额外的版本,允许我们提供自己定义的操作来代替默认运算符. 例如,sort算法默 ...
- (转)OpenVPN使用HTTP代理连接服务器
原文地址:http://www.365mini.com/page/18.htm 在一些公司或者其他受限的网络环境中,使用的是HTTP代理服务器上网.在这种情况下,使用OpenVPN客户端可能无法连接服 ...
- JavaScript平常会跳的坑系列(一)
function Foo() { //定义foo函数 getName = function () { console.log('1');}; console.log(this); return thi ...
- (转)Eclipse中junit框架的使用——单元测试
[转]junit浅学笔记一 JUnit是一个回归测试框架(regression testing framework).Junit测试是程序员测试,即所谓白盒测试,因为程序员知道被测试的软件如何(How ...
- 几种工具反编译被编译好的DLL文件
我们平时在工作中经常会遇到一些已经被编译后的DLL,而且更加麻烦是没有源代码可以进行修改,只能针对这个DLL的文件进行修改才能得到我们想要的结果:本文将通过一个实例来演示如果完成一个简单的修改;我们将 ...
- 什么是SysWow64
转自 什么是SysWow64 Wow!什么是Wow64 64位的Windows并不是简单地把所有东西都编译成64位就万事大吉的.关于64位的CPU应该做成什么样子,Intel和AMD曾有各自的打算.A ...
- TPL(Task Parallel Library)多线程、并发功能
The Task Parallel Library (TPL) is a set of public types and APIs in the System.Threading and System ...