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. 最新模仿ios版微信应用源码

    这个是刚刚从那个IOS教程网http://ios.662p.com分享来的,也是一个很不错的应用源码,仿微信基本功能.基于XMPP服务器的即时通信以及交友客户端. ----第一期代码的功能如下---- ...

  2. 最常用的MySQL命令语句

    e良师益友网导读:MySQL数据库是应用最广的数据库之一,在MySQL数据库中有各种各样的命令调用语句,在平常工作中非常实用的命令,对于初学者来说,掌握文中的MySQL命令语句,是非常实用的,下面我们 ...

  3. JQuery 预热

    这是第一次在博客园写随笔,之所以有这样的冲动是因为每次看到很多园友不断的发表文章,记录下自己的点点滴滴,内心就在不断的忏悔,我很敬佩这种人,不管他们表达的东西是初级还是精辟,我认为只要去坚持写了就是一 ...

  4. Class<Object>与Class<?>有何区别呢

    1.? 和 Object 差不多,不过还是有差别.在这种情况下: class<? extends SomeClass> , Object就不能用了 Object是一个具体的类名,而?是一个 ...

  5. mac下安装pcntl

     Now you need to find out what version of PHP is installed on OSX $ php -vPHP 5.3.10 with Suhosin-Pa ...

  6. [总结]Android系统体系结构

    Android 从图中可以看出Android主要的组成部分,其中底层是Linux的内核,包括的主要就是文件.内存.系统资源等的管理,Google在这部分的工作主要就是电源管理和一部分驱动,并且整合上层 ...

  7. Review PHP设计模式之——观测模式

    观测模式: <?php class car implements SplSubject{ private $carName; //车的类型 private $carState=0; //车的状态 ...

  8. C++ 编写 CorelDRAW CPG 插件例子(2)—ClearFill

    这是另一个例子: 贴上主要代码: #include "stdafx.h" #include <tchar.h> #import "libid:95E23C91 ...

  9. 学习VirtualEnv和Nginx+uwsgi用于django项目部署

    以下叙述中用到的操作系统:Linux CentOS 6.X. 最近几天了解一下VirtualEnv,Apache+Daemon mode,Nginx+uwsgi的概念,并且在项目中实验性部署了一下(目 ...

  10. c# 代理IP获取通用方法

    调用: ConcurrentQueue<string> proxyIpQueue = new ConcurrentQueue<string>(); Grab_ProxyIp(p ...