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

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
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 10003
/*
给定词典中的单词,要求检查合法的单词
如果词典中单词与该单词长度相等检查能否替换
否则如果两个单词长度之差绝对值小于一 检查能否添加删除
*/
vector<string> dict;
bool f = false;
bool Compare(string &s,string &l)
{
string::iterator p1 = s.begin(),p2 = l.begin();
int cnt = ;
while(p1!=s.end())
{
if(*p1!=*p2)
{
p2++;
cnt++;
if(cnt>)
return false;
}
else
{
p1++;
p2++;
}
}
return true;
}
bool Replace(string &word,string &dict)
{
int l = word.size();
int cnt = ;
for(int i=;i<l;i++)
{
if(word[i]!=dict[i])
cnt++;
if(cnt>)
return false;
}
return true;
}
int main()
{
dict.resize();
int cnt = ;
while(cin>>dict[cnt++])
{
if(dict[cnt-][]=='#')
{
cnt--;
break;
}
}
string word;
while(cin>>word)
{
vector<string> ans;
if(word[]=='#')
break;
int l1 = word.size();
f = false;
bool find = false;
for(int i=;i<cnt;i++)
{
int l2 = dict[i].size();
if(l1==l2)
{
if(word==dict[i])
{
find = true;
f = false;
break;
}
if(Replace(word,dict[i]))
{
f = true;
ans.push_back(dict[i]);
}
}
else if(l1==l2+)
{
if(Compare(dict[i],word))
{
f = true;
ans.push_back(dict[i]);
}
}
else if(l2==l1+)
{
if(Compare(word,dict[i]))
{
f = true;
ans.push_back(dict[i]);
}
}
}
cout<<word;
if(!f&&find)
cout<<" is correct";
else
{
cout<<":";
for(int i=;i<ans.size();i++)
cout<<" "<<ans[i];
}
cout<<endl;
}
}

Spell checker POJ 1035 字符串的更多相关文章

  1. Spell checker - poj 1035 (hash)

      Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22541   Accepted: 8220 Description Yo ...

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

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

  3. POJ 1035:Spell checker

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

  4. poj 1035 Spell checker

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

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

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

  6. POJ1035——Spell checker(字符串处理)

    Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...

  7. poj 1035 纯正的字符串水

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 22673   Accepted: 8258 De ...

  8. POJ 1035 代码+具体的目光

    Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...

  9. Spell checker

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

随机推荐

  1. 【Kafka】《Kafka权威指南》——从Kafka读取数据

    应用程序使用 KafkaConsumer向 Kafka 订阅主题,并从订阅的主题上接收消息 . 从 Kafka 读取数据不同于从其他悄息系统读取数据,它涉及一些独特的概念和想法.如果不先理解 这些概念 ...

  2. $stylus美化$

    一直在用洛谷 当然不一定是洛谷 其他的网站也可以用 比如说codeforces 还是决定要美化一波 首先去找一个插件 叫做 stylus stylus下载的很多 我不想过多说明. Google和QQ浏 ...

  3. Win7 + VS2015 + Python3.6编译

    0. 下载安装hg. http://bitbucket.org/tortoisehg/files/downloads/tortoisehg-4.0.1-x64.msi 1. 下载Python3.6源代 ...

  4. Application、Activity Stack 和 Task的区别

    Application类 Application和Activity,Service一样是Android框架的一个系统组件,当Android程序启动时系统会创建一个Application对象,用来存储系 ...

  5. 336 Palindrome Pairs 回文对

    给定一组独特的单词, 找出在给定列表中不同 的索引对(i, j),使得关联的两个单词,例如:words[i] + words[j]形成回文.示例 1:给定 words = ["bat&quo ...

  6. [转]android 获取 imei号码

    核心代码: Imei = ((TelephonyManager) getSystemService(TELEPHONY_SERVICE)) .getDeviceId(); 1.加入权限 在manife ...

  7. 在Windows2003安装配置Bitvise SSH Server后,不能使用软件内建立的用户登录!

    Google:  I can only log in with an administrator account - attempting to log in with a regular accou ...

  8. C# 利用反射进行类型转换

    /// <summary> /// 父类转子类 /// </summary> /// <typeparam name="TParent">< ...

  9. Linq学习(四)-联合查询

    一.本将主要介绍 Union.Concat.Intersect.Except的使用操作 1.Union 查询昵称中带有Friend和带有Lee的用户 Linq (from a in Blog_User ...

  10. Python--10、线程

    线程 每个进程里都有一个控制线程,进程不是一个执行单位,线程是执行单位,进程是资源单位(资源隔离).进程下可以开多个线程,多线程共享进程内的资源.创建线程的速度比创建进程的速度快,因为创建线程不需要再 ...