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. DP入门数塔问题

    在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?        已经告诉你了,这 ...

  2. asp.net 中使用less

    首先 ,需要知道 whats the less; 实际上less 只是针对css比较难于维护和抽象这种现象,而创造的一个工具. 然后,在抛开语言环境的情况下(例如.net 是vs环境,java是ecl ...

  3. Mac OS 踩坑指南

    前言 其实mac os本身还是很不错的,软硬结合使得其性能.效率.续航得到了很好的优化. 但是毕竟是一个"小众"操作系统,很多在Win上已经用习惯的东西在这里都没有,或者完全不一样 ...

  4. DTcms列表隔行换色;loop自带行号

    <%loop cdr2 bcategoryList%> <%if(cdr2__loop__id==1)%> <a class="no-bg" href ...

  5. PHP获取当前时间的毫秒数(yyyyMMddHHmmssSSS)

    1 second = 1000 millisecond = 1000,000 microsecond = 1000,000,000 nanosecond php的毫秒是没有默认函数的,但提供了一个mi ...

  6. 超棒的阿里巴巴矢量图标库——支持IE6

    Iconfont.cn 是由阿里巴巴UX部门推出的矢量图标管理网站,也是国内首家推广Webfont形式图标的平台.网站涵盖了1000多个常用图标并还在持续更新 中,Iconfont平台为用户提供在线图 ...

  7. spark向量

    转自 1.本地向量MLlib的本地向量主要分为两种,DenseVector和SparseVector,顾名思义,前者是用来保存稠密向量,后者是用来保存稀疏向量,其创建方式主要有一下三种(三种方式均创建 ...

  8. Linux进程间通信IPC学习笔记之同步二(Posix 信号量)

    Linux进程间通信IPC学习笔记之同步二(Posix 信号量)

  9. C/C++错误分析errno,perror,strerror和GetLastError()函数返回的错误代码的意义

    在C语言编译中,经常会出现一些系统的错误,这些错误如果在编译的时候不能很好的“预见”,会使系统“崩溃”,常见的捕获错误函数有: errno #include<errno.h> 这个变量是程 ...

  10. Servlet一次乱码排查后的总结(转)

    原文地址:http://my.oschina.net/looly/blog/287255 由来 在写一个小小的表单提交功能的时候,出现了乱码,很奇怪request上来的参数全部是乱码,而从数据库查询出 ...