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

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增加了一个字符

4删除了一个字符

输出得到的结果。

简单题,对于字符串的枚举,就看其长度等于,大于1,小于1,之后比较相等的字符数量即可,符合的输出。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; vector<string>dic;
vector<string>modi; void solve(string test)
{
modi.clear();
int i;
int len=dic.size(); for(i=0;i<len;i++)
{
if(dic[i]==test)
{
cout<<test<<" is correct"<<endl;
return;
}
if(dic[i].length()==test.length())
{
int result=0,j;
for(j=0;j<test.length();j++)
{
if(dic[i][j]==test[j])
result++;
}
if(result==test.length()-1)
{
modi.push_back(dic[i]);
}
}
else if(dic[i].length()+1==test.length())
{
int result=0,j=0,k=0;
for(j=0;j<dic[i].length()&&k<test.length();k++)
{
if(dic[i][j]==test[k])
{
result++;
j++;
}
}
if(result==dic[i].length())
{
modi.push_back(dic[i]);
}
}
else if(dic[i].length()-1==test.length())
{
int result=0,j=0,k=0;
for(k=0;k<test.length()&&j<dic[i].length();j++)
{
if(dic[i][j]==test[k])
{
result++;
k++;
}
}
if(result==test.length())
{
modi.push_back(dic[i]);
}
}
} if(modi.size())
{
cout<<test<<":";
for(i=0;i<modi.size();i++)
{
cout<<" "<<modi[i];
}
cout<<endl;
}
else
cout<<test<<":"<<endl;
} int main()
{
string test;
dic.clear();
while(cin>>test)
{
if(test=="#")
break;
dic.push_back(test);
}
while(cin>>test)
{
if(test=="#")
break;
solve(test);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

POJ 1035:Spell checker的更多相关文章

  1. 【POJ 1035】Spell checker

    题 题意 每个单词,如果字典里存在,输出”该单词 is correct“:如果字典里不存在,但是可以通过删除.添加.替换一个字母得到字典里存在的单词,那就输出“该单词:修正的单词”,并按字典里的顺序输 ...

  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: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

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

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

  5. Spell checker POJ 1035 字符串

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

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

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

  7. Spell checker

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

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

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

  9. Code Spell Checker & VSCode 单词拼写验证

    Code Spell Checker & VSCode 单词拼写验证 https://marketplace.visualstudio.com/items?itemName=streetsid ...

随机推荐

  1. Nginx配置的一些说明(添加https证书)

    server { listen 443 ssl; #监听https 443端口 server_name www.XXXX.com; client_max_body_size 260M; #这下面的就是 ...

  2. JS - 判断字符串某个下标的值

    <html><body> <script type="text/javascript"> var str="0123456789!&q ...

  3. MySQL 中的数据库名称、数据表名称、字段名称

    如何查询Oracle,Sql Server,MySQL 中的数据库名称.数据表名称.字段名称 分类: Database2012-09-24 22:16 7034人阅读 评论(0) 收藏 举报 数据库s ...

  4. RAM和ROM的区别

    区别如下: 1.概念 RAM(random access memory)即随机存储内存,这种存储器在断电时将丢失其存储内容,故主要用于存储短时间使用的程序.ROM(Read-Only Memory)即 ...

  5. Gym - 101190F Foreign Postcards (期望dp)

    题意:有n张标有“C”或“F”的卡片. 1.随机取前k张(1<=k<=n) 2.若这k张的第一张为“C”,则不翻转,否则,全部翻转这k张. 3.然后处理剩下的n-k张 4.重复步骤1~3直 ...

  6. 读取docx表格中的信息

    参考了 http://blog.csdn.net/qq_34475777/article/details/62055523 http://www.cnblogs.com/deepwaterplan/a ...

  7. 十五、SAP自定义结构体

    一.SAP的结构体是以BEGIN OF开始,以END OF结尾,代码如下: 二.输出结果如下

  8. 对于python 3.x与python2.x中新型类的继承特性总结

    (1)一般性继承特性 """ 该文件对于python 3.x 及python 2.x的New-style 类的一般性继承特性进行了说明和测试. (1)实例的继承特性:搜寻 ...

  9. MacOS通过ssh连接基于Virtualbox的Ubuntu虚拟机

    以前总是用Windows软件putty进行ssh连接,今天尝试使用macos. 实验环境:主机:macos 10.15.3 客户机:Ubuntu 18.04 默认情况下,Ubuntu没有安装SSH,需 ...

  10. Kubernetes-基于helm安装部署高可用的Redis及其形态探索

    首先是一些关于redis的介绍和其在K8S上的安装过程:https://www.kubernetes.org.cn/3974.html 1.1部署形态 通过上述地址的教程,可以完成redis 的安装和 ...