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 ...
随机推荐
- RING0,RING1,RING2,RING3
Intel的CPU将特权级别分为4个级别:RING0,RING1,RING2,RING3.Windows只使用其中的两个级别RING0和RING3,RING0只给操作系统用,RING3谁都能用.如果普 ...
- NSIndexPath 延伸
转载自:http://my.oschina.net/u/2560887/blog/602095?fromerr=Dy4vj5Jd 这个类的实例描述了一个嵌套数组中特定节点的路径,一般叫做索引路径.1. ...
- VideoView的视频播放
//-------------onCreate方法中----------------------- VideoView video_view = (VideoView) findViewById(R. ...
- HBase性能优化方法总结(一):表的设计
本文主要是从HBase应用程序设计与开发的角度,总结几种常用的性能优化方法.有关HBase系统配置级别的优化,可参考:淘宝Ken Wu同学的博客. 下面是本文总结的第一部分内容:表的设计相关的优化方法 ...
- java面向对象_接口
java接口 interface,是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类,编写接口的方式和类很相似,但 ...
- android 在代码中使用 #ffffff 模式 设置背景色
differentsum.setBackgroundColor(Color.parseColor("#F3733F"));
- 使用for循环还是foreach循环?
很多时候我们很自然的认为,for循环的时候使用foreach和原来的for循环用下标的方式遍历是相同的. 而且因为foreach循环写法简单,很容易理解,而且少去了很多麻烦的变量,所以估计在学会使用f ...
- bluehost 邮箱设置问题
问题描述: e-elitech.com域名,elitechus.com域名均在阿里云注册,en.e-elitech.com解析到bluehost虚拟主机,www.elitechus.com也解析到bl ...
- js所有函数集合
lick() 对象.click() 使对象被点击. closed 对象.closed 对象窗口是否已关闭true/false clearTimeout(对象) 清除已设置的setTimeout对象 c ...
- 浅谈ajax的优点与缺点
AJAX (Asynchronous Javascript and XML) 是一种交互式动态web应用开发技术,该技术能提供富用户体验. 完全的AJAX应用给人以桌面应用的感觉.正如其他任何技术,A ...