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. android中的简单animation(四)3D transition

    animation_main_screen.xml: <?xml version="1.0" encoding="utf-8"?> <Fram ...

  2. 困惑我的x++和++x;

    刚学习C语言时X++和++X非常不解 目前有了新的领悟 1.X++ int x=0; int z=x++; 此时z?x? 这个问题可以分两步思考 第一步:先把x的值赋予z,此时z=x=0; 第二步:x ...

  3. 【LOJ3043】「ZJOI2019」线段树

    题面 问题可以转化为每次区间覆盖操作有 \(\frac{1}{2}\) 的概率进行,求标记和的期望.于是我们只要求出所有点有标记的概率即可. 我们设 \(f_i\) 表示节点 \(i\) 有标记的概率 ...

  4. pyhton scipy最小二乘法(scipy.linalg.lstsq模块)

    最小二乘法则是一种统计学习优化技术,它的目标是最小化误差平方之和来作为目标J(θ)J(θ),从而找到最优模型. 7. SciPy最小二乘法 最小二乘法则是一种统计学习优化技术,它的目标是最小化误差平方 ...

  5. .NET via C#笔记12——泛型

    12 泛型 使用值类型作为参数的泛型容器,传入值类型的参数时,不需要进行装箱 12.1 FCL中的泛型 System.Array中提供了很多泛型方法 AsReadOnly BinarySearch C ...

  6. spring boot rest api exception解决方案

    1.控制器级别@ExceptionHandler public class FooController{           //...     @ExceptionHandler({ CustomE ...

  7. TextView标签的属性和跑马灯效果

    text:显示的内容 textSize:文本的大小 textColor:文本的颜色 visibility:可见性  默认可见,invisible:表示不可见,但对控件的显示区域做了保留 gone:隐藏 ...

  8. 国产超低功耗蓝牙5.0 PHY6202替换NRF51822

    现在在智能穿戴领域市场不断的追求低功耗.低成本的蓝牙芯片.蓝牙芯片目前除了Dialog公司研制蓝牙芯片是最求超低功耗的但是对于其它性能上还比较满足不了其它领域的功能,另外NORDIC.TI的蓝牙芯片虽 ...

  9. Django——整体结构/MVT设计模式

    MVT设计模式 Models      封装数据库,对数据进行增删改查; Views        进行业务逻辑的处理 Templates  进行前端展示 前端展示看到的是模板  -->  发起 ...

  10. 二十、SAP中定义内表

    一.内表相当于传统语言的多维数组的东西,定义一个内表有以下2个方式