Spell checker

Description
You, as a member of a development team for a new spell checking program, are to write a module that will check the correctness of given words using a known dictionary of all correct words in all their forms.
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:
?deleting of one letter from the word;
?replacing of one letter in the word with an arbitrary letter;
?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 first part of the input file contains all words from the dictionary. Each word occupies its own line. This part is finished by the single character '#' on a separate line. All words are different. There will be at most 10000 words in the dictionary.
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
Write to the output file exactly one line for every checked word in the order of their appearance in the second part of the input file. If the word is correct (i.e. it exists in the dictionary) write the message: " is correct". If the word is not correct then write this word first, then write the character ':' (colon), and after a single space write all its possible replacements, separated by spaces. The replacements should be written in the order of their appearance in the dictionary (in the first part of the input file). If there are no replacements for this word then the line feed should immediately follow the colon.
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

题目大意:

    给定一个字典,判断输入的数是否在字典中。

    若不在字典再判断 是否可以通过以下三个变性中的一个变成字典中的字符串。

    1)增加一个字符 2)删掉一个字符 3)改变一个字符

解题思路:

    字符串处理,先判断在不在字典中。

    不在的话再判断是否可以变性为字典中的字符串。注意判断语句的写法即可。

Code:

 /*************************************************************************
> File Name: poj1035.cpp
> Author: Enumz
> Mail: 369372123@qq.com
> Created Time: 2014年10月19日 星期日 15时27分59秒
************************************************************************/ #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<list>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#define MAXN 1000
using namespace std;
char dic[][];
char word[];
int Num_dic;
bool Find_same(char *word)
{
bool ok=;
for (int i=;i<=Num_dic;i++)
if (strcmp(dic[i],word)==)
{
ok=;
break;
}
return ok;
}
void Find_opt(char *word)
{
for (int i=;i<=Num_dic;i++)
{
int len_word=strlen(word);
int len_dic=strlen(dic[i]);
if (len_word==len_dic)
{
int cnt=;
for (int j=;j<=len_word-;j++)
if (dic[i][j]!=word[j]) cnt++;
if (cnt==)
printf(" %s",dic[i]);
}
else if (len_word-len_dic==)
{
int k1=,k2=,cnt=;
while ()
{
if (k1==len_dic&&k2==len_word)
break;
if (cnt>=)
break;
if (dic[i][k1]==word[k2])
k1++,k2++;
else k2++,cnt++;
}
if (cnt==)
printf(" %s",dic[i]);
}
else if (len_dic-len_word==)
{
int k1=,k2=,cnt=;
while ()
{
if (k1==len_dic&&k2==len_word)
break;
if (cnt>=)
break;
if (dic[i][k1]==word[k2])
k1++,k2++;
else k1++,cnt++;
}
if (cnt==)
printf(" %s",dic[i]);
}
}
}
int main()
{
Num_dic=;
while ()
{
scanf("%s",dic[Num_dic]);
if(strcmp(dic[Num_dic],"#")==)
{
Num_dic--;
break;
}
else Num_dic++;
}
while ()
{
scanf("%s",word);
if (strcmp(word,"#")==)
break;
if (Find_same(word))
printf("%s is correct\n",word);
else
{
printf("%s:",word);
Find_opt(word);
printf("\n");
}
}
return ;
}

POJ1035——Spell checker(字符串处理)的更多相关文章

  1. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  2. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  3. poj1035 Spell checker

    这题目比较简单,把思路搞清楚就可以啦. #include <stdio.h> #include <string.h> +][]; int init(){ ; while(~sc ...

  4. Spell checker POJ 1035 字符串

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 25426   Accepted: 9300 De ...

  5. POJ 1035:Spell checker

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22574   Accepted: 8231 De ...

  6. Spell checker

     Spell checker Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  7. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

  8. Spell checker(暴力)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20188   Accepted: 7404 De ...

  9. [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 De ...

随机推荐

  1. OCI-DML-更新数据库中不存在的字段

    用gtest来测试oracle中oci方式的SQL语句操作,在测试update数据库中不存在的异常案例的时候,日志没有报错,但是结束后跳出了数据库连接 gtest也没有给出正常的结果,本身update ...

  2. 视酷即时通讯系统应用源码 V1.0

    视酷即时通讯系统(原创),成熟稳定,拥有和微信一样强大的功能不再是梦,节省几个月研发时间迅速融合进项目中: 1.首家支持聊天室群聊 2.支持和微信一样的语音聊天,可以显示时长.未读状态,自动轮播未读语 ...

  3. web组件新学--layer

    在之前项目后台管理界面开发中,不知道有layer这样好用的组件,我的内心是这样的的...呀!这个框架有弹框,哈哈哈,好开心,不用自己写遮罩层,不用自己写弹框,好开森.. 当知道有layer之后.... ...

  4. c#怎么获取当前页面的url

    Request.ApplicationPath: /testwebRequest.CurrentExecutionFilePath: /testweb/default.aspxRequest.File ...

  5. ecshop中无限处理分类

    数据库表记录结构 <?php $sql = "SELECT c.cat_id, c.cat_name, c.measure_unit, c.parent_id, c.is_show, ...

  6. [OpenXml] Read/Write row/cell from excel

    public static void test(){ using (SpreadsheetDocument document = SpreadsheetDocument.Open("test ...

  7. 浏览器的visibilitychange 事件ie10以下不兼容

    方法1, <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  8. CentOS 6.4 中安装部署 Nutch 1.7

    1.配置SSH 自行查阅相关资料 2.安装JDK,配置Java环境 自行查阅相关资料 3.安装SVN [root@master ~]# yum install -y subversion 通过SVN签 ...

  9. WordPress 模板常用函数

    WordPress 基本模板文件 一套完整的 WordPress 模板应至少具有如下文件: style.css : CSS(样式表)文件 index.php : 主页模板 archive.php : ...

  10. 开博第一篇:DHT 爬虫的学习记录

    经过一段时间的研究和学习,大致了解了DHT网络的一些信息,大部分还是参会别人的相关代码,一方面主要对DHT爬虫原理感兴趣,最主要的是为了学习python,大部分是别人的东西原理还是引用别人的吧 DHT ...