spell checking
Spell checker
Description
If the word is absent in the dictionary then it can be replaced by correct words (from the dictionary) that can be obtained by one of the following operations:
(1)deleting of one letter from the word;
(2)replacing of one letter in the word with an arbitrary letter;
(3)inserting of one arbitrary letter into the word.
Your task is to write the program that will find all possible replacements from the dictionary for every given word.
Input
The next part of the file contains all words that are to be checked. Each word occupies its own line. This part is also finished by the single character '#' on a separate line. There will be at most 50 words that are to be checked.
All words in the input file (words from the dictionary and words to be checked) consist only of small alphabetic characters and each one contains 15 characters at most.
Output
Sample Input
i
is
has
have
be
my
more
contest
me
too
if
award
#
me
aware
m
contest
hav
oo
or
i
fi
mre
#
Sample Output
me is correct
aware: award
m: i my me
contest is correct
hav: has have
oo: too
or:
i is correct
fi: i
mre: more me 注:本例程序有些许问题,有待进一步改进:
#include<iostream>
#include<string.h>
using namespace std;
int DictNum=0; //字典中字符的个数
int WordNum=0; //单词计算器
char dict[10001][16]; //数据库中的单词
char word[51][16]; //要操作的单词
int K=0;
int main()
{
void Input(); //输入函数
bool Change(char *word,char *list); //改变字符函数
bool Add(char *word,char *list); //增加字符函数
bool Delete(char *word,char *list); //删除字符函数
int *DictLen=new int[DictNum]; //记录词库中各个单词的长度
Input();
// cout<<"DictNum=="<<DictNum<<endl;
// cout<<"WordNum=="<<WordNum<<endl;
for(int i1=0;i1<DictNum;i1++) DictLen[i1]=strlen(dict[i1]); //得到词库中各单词的长度
// for(int i1=0;i1<DictNum;i1++) cout<<DictLen[i1]<<' ';
// cout<<endl;
for(int i=0;i<WordNum;i++) //遍历要操作的每一个单词
{
//cout<<"K=="<<K++<<endl;
bool flag=false; //标记字典中是否有单词word[i];
//cout<<"flag=="<<flag<<endl;
int len=strlen(word[i]); //求得该单词的长度
//cout<<"len=="<<len<<endl;
int pa=0; //记录多个与当前操作单词相似
//cout<<"pa=="<<pa<<endl;
int *address=new int[WordNum]; //记录要操作的单词通过变化得到的单词在dict中的下标
for(int j=0;j<DictNum;j++)
{
if(len==DictLen[j])
{
if(!strcmp(word[i],dict[j])) //词库中存在此单词
{
cout<<"比较后的结果1(匹配):"<<dict[j]<<endl;
flag=true;
break;
}
if(Change(word[i],dict[j]))
{
cout<<"比较后的结果2(改变):"<<dict[j]<<endl;
address[pa++]=j;
cout<<"dict[address[pa-1]]=="<<dict[address[pa-1]]<<endl;
}
}
else if((len-DictLen[j])==1)
{
if(Delete(word[i],dict[j]))
{
cout<<"比较后的结果(删除):"<<dict[j]<<endl;
address[pa++]=j;
}
}
else if((DictLen[j]-len)==1)
{
if(Add(word[i],dict[j]))
{
cout<<"比较后的结果(增加):"<<dict[j]<<endl;
address[pa++]=j;
}
}
}
cout<<"pa=="<<pa<<endl;
for(int k=0;k<pa;k++)
{
cout<<address[k]<<' ';
}
cout<<endl;
if(flag) cout<<word[i]<<" is correct"<<endl;
else
{
cout<<word[i]<<": ";
for(int i2=0;i2<pa;i2++)
cout<<dict[ address[i2] ]<<' ';
cout<<endl;
}
delete address;
}
delete DictLen;
return 0;
}
void Input()
{
while(cin>>dict[DictNum]&&dict[DictNum++][0]!='#');
while(cin>>word[WordNum]&&word[WordNum++][0]!='#');
DictNum--;
WordNum--;
}
bool Change(char *word,char *list)
{
cout<<"1111"<<endl;
int dif=0;
while(*word)
{
if(*(word++)!=*(list++))
{
dif++;
if(dif>1) return false;
}
}
return true;
}
bool Add(char *word,char *list)
{
cout<<"2222"<<endl;
int dif=0;
while(*list)
{
if(*(list++)!=*(word++))
{
word--;
dif++;
if(dif>1) return false;
}
}
return true;
}
bool Delete(char *word,char *list)
{
cout<<"3333"<<endl;
int dif=0;
while(*word)
{
if(*(word++)!=*(list++))
{
list--;
dif++;
if(dif>1) return false;
}
}
return true;
}
spell checking的更多相关文章
- git-gui:使用终端打开以后出现错误提示 Spell checking is unavable
参考链接:http://www.lai18.com/content/10706682.html 安装了git-gui,打开以后出现以下提示: Spell checking is unavable: e ...
- 1.7.7 Spell Checking -拼写检查
1. SpellCheck SpellCheck组件设计的目的是基于其他,相似,terms来提供内联查询建议.这些建议的依据可以是solr字段中的terms,外部可以创建文本文件, 或者其实lucen ...
- Spell checker
Spell checker Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- [solr] - spell check
solr提供了一个spell check,又叫suggestions,可以用于查询输入的自动完成功能auto-complete. 参考文献: https://cwiki.apache.org/conf ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- Spell checker(暴力)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20188 Accepted: 7404 De ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
- 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 ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
随机推荐
- JS-日期框、下拉框、全选复选框
<!-- 下拉框 --><link rel="stylesheet" href="static/ace/css/chosen.css" /&g ...
- regress
#! /bin/ksh ############### ### UAT ### ############### export ENVS=/test/change/env/env_test.sq ...
- java模式:深入单例模式
原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://devbean.blog.51cto.com/448512/203501 在GoF ...
- PostConstruct注解
应用场景:当你需要往Bean里注入一个其父类中定义的属性,而你又无法复写父类的属性或属性的setter方法时 public class UserDaoImpl extends HibernateDao ...
- FRP 浅析
一.Reactive? 请先看一个非常简单的小应用,它允许用户在一个搜索输入框里输入关键词,然后在其下方的结果区域实时显示从Flicker网站搜索得到的图片,当用户输入的关键词发生变化,显示的图片也会 ...
- Box2d b2World的RayCast方法
RayCast方法: world.RayCast(callback:Function,point1:b2Vec2,point2:b2Vec2); * callback 回调函数 * point1 射线 ...
- javascript预编译
刚学前端的小白,第一次写博客,难免有点幼稚.以后每周写两次博客,慢慢积累. 笨鸟不必先飞,但一定是最后一个留下的.加油! JS的预编译定义 在一段程序执行前,js会把var和function这两个关键 ...
- 激活OFFICE2010时,提示choice.exe不是有效的win32程序
我在安装office2010破解版时,提示choice.exe不是有效的win32应用程序 删除choice.exe再激活,按提示找到目录删掉这个文件,需要设置显示隐藏文件夹
- aspx基础开始
<%@ Page Language="C#" Debug="true" trace="false" validateRequest=& ...
- SEO优化之 主页上加上nofollow
<a href=http://www.主页.cn/ rel=”nofollow”>这里是锚文字</a> <光年日志分析系统>来分析抓取比较多的是哪个网页,没用的no ...