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 ...
随机推荐
- sdio/sd/mmc architecture
三个驱动mmc_core.ko mmc_block.ko omap_hsmmc.ko 读懂一个协议的架构有利于学习源码 参考了 http://processors.wiki.ti.com/index. ...
- iperf linux版本移植到android (使用工具链方式不是使用Android.mk)
由于很多程序是用makefile编译linux应用程序的,如果移植到android就要重新写Android.mk,对于不熟悉这个的人来说,特别麻烦,所以这里介绍只修改makefile就能移植到andr ...
- iOS \'The sandbox is not sync with the Podfile.lock\'问题解决
iOS \'The sandbox is not sync with the Podfile.lock\'问题解决 HUANGDI 发表于 2015-02-27 09:51:13 问题描述: gith ...
- Spring Boot 系列教程14-动态修改定时任务cron参数
动态修改定时任务cron参数 不需要重启应用就可以动态的改变Cron表达式的值 不能使用@Scheduled(cron = "${jobs.cron}")实现 DynamicSch ...
- phpStudy环境配置多个站点,绑定域名
经常做网站的朋友,往往要在自已的电脑同时建立多个站点,而phpstudy这款软件就能很好的解决这个问题,大家看下图 点击上图中的 其它选项菜单 ,就会弹出下面的对话框,然后点击 站点域名管理 然 后在 ...
- HDU<1372>/bfs
题目连接 简单bfs搜索 #include <set> #include <map> #include <cmath> #include <queue> ...
- GUI矩形、椭圆、线、框架
所有的Swing组件必须由时间调度线程(event dispatch thread)进行配置,线程将鼠标点击和键盘敲击控制转移到用户接口组件.下面的代码片段是事件调度线程中的执行代码: EventQu ...
- poj 1654 Area(计算几何--叉积求多边形面积)
一个简单的用叉积求任意多边形面积的题,并不难,但我却错了很多次,double的数据应该是要转化为long long,我转成了int...这里为了节省内存尽量不开数组,直接计算,我MLE了一发...,最 ...
- php 创建删除数据库
<?php $dbhost = 'localhost:3306'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, ...
- Linux 监控文件事件
某些应用程序需要对文件或者目录进行监控,来侦测其是否发生了某些事件.Linux很贴心的为我们提供了inotify API,也是Linux的专有. inotify API 在使用之前一定要有一个inot ...