POJ1035——Spell checker(字符串处理)
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(字符串处理)的更多相关文章
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- poj1035 Spell checker
这题目比较简单,把思路搞清楚就可以啦. #include <stdio.h> #include <string.h> +][]; int init(){ ; while(~sc ...
- Spell checker POJ 1035 字符串
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25426 Accepted: 9300 De ...
- POJ 1035:Spell checker
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22574 Accepted: 8231 De ...
- Spell checker
Spell checker Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- 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 ...
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18693 Accepted: 6844 De ...
随机推荐
- IIS安装Web Deploy之后没有显示右键菜单
Bug描述: 使用IIS自带的"Web平台安装程序"安装完Web Deploy组件之后,鼠标右键点击网站,弹出的菜单中并没有新增的"部署"选项. Bug解决: ...
- Java数字格式化输出时前面补0
Java数字格式化输出时前面补0 星期日 2014年11月30日| 分类: Java /** * 里数字转字符串前面自动补0的实现. * */ public class TestString ...
- L009-oldboy-mysql-dba-lesson09
L009-oldboy-mysql-dba-lesson09 mysql> grant replication salve,replication client on *.* to ‘repl_ ...
- 从 Java 代码逆向工程生成 UML 类图和序列图
from:http://blog.itpub.net/14780914/viewspace-588975/ 本文面向于那些软件架构师,设计师和开发人员,他们想使用 IBM® Rational® Sof ...
- css定义的权重
以下是权重的规则:标签的权重为1,class的权重为10,id的权重为100,以下例子是演示各种定义的权重值: /*权重为1*/ div{ } /*权重为10 ...
- Stimulsoft Reports报表工具
关于第三方的报表工具,网上的种类有很多,一些专门做报表工具的公司,还针对不同平台语言做了分别处理.总之功能都很强大,比较流行和使用广泛的貌似还是国外的产品,版本收费和中文资料匮乏,这都是不可避免的问题 ...
- 防止非授权用户调用DLL
1.首先要创建一个密钥文件(*.snk)
- mac下安装redis
安装php_redis.so 首先用git从https://github.com/nicolasff/phpredis下载源码.然后依次执行以下命令 sudo /Applications/XAMPP/ ...
- Python Generators vs Iterators
http://stackoverflow.com/questions/2776829/difference-between-python-generators-vs-iterators iterato ...
- Python 信号量
信号的概念 信号(signal)-- 进程之间通讯的方式,是一种软件中断.一个进程一旦接收到信号就会打断原来的程序执行流程来处理信号. 几个常用信号: SIGINT 终止进程 中断进 ...