POJ 1035:Spell checker
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 22574 | Accepted: 8231 |
Description
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 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 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的更多相关文章
- 【POJ 1035】Spell checker
题 题意 每个单词,如果字典里存在,输出”该单词 is correct“:如果字典里不存在,但是可以通过删除.添加.替换一个字母得到字典里存在的单词,那就输出“该单词:修正的单词”,并按字典里的顺序输 ...
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18693 Accepted: 6844 De ...
- Spell checker POJ 1035 字符串
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 25426 Accepted: 9300 De ...
- POJ 1035 代码+具体的目光
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 19319 Accepted: 7060 Descri ...
- Spell checker
Spell checker Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
- Code Spell Checker & VSCode 单词拼写验证
Code Spell Checker & VSCode 单词拼写验证 https://marketplace.visualstudio.com/items?itemName=streetsid ...
随机推荐
- shell教程——bash入门
创建shell文件 vim test.sh 写内容 #!/bin/bash echo "Hello World !" 使脚本具有执行权限 chmod +x ./test.sh 执行 ...
- Stm32CubeMx lwip+freeRTOS TCP 服务
如何添加lwip参照上一篇 stm32CubeMx lwip + freeRTOS 今天讲一下,如何添加TCP服务 LwIP 提供了三种编程接口,分别为 RAW/Callback API.NETC ...
- 剑指offer第12题打印从1到n位数以及大整数加法乘法
字符和数字加减就是字符的ASCII码和数字直接加减. 方法一: 1)在字符串操作中给一个整形数字加(字符0)就是把它转化为字符,当然给一个字符减去(字符0)就可以把它转化为数字了:如果确实是最后 ...
- es和数据类型
js=es+dom+bom,dom和bom前面已经讲完了 es是js的本体,是指数据类型,和对于数据的操作手段,他的版本更新得很快 这些功能不是html文件提供的,也不是浏览器提供的,即使脱离了dom ...
- SQL添加列、非空、默认值
use MarcoBarcode go alter table [dbo].[WorkOrderRepairSheet] ADD needRepair int go ALTER TABLE [dbo] ...
- JavaScript的调用
1 方法调用模式 var myObject = { value : 0, increment : function(inc) { alert('hi'); } }; myObject.incremen ...
- 一文详解scala泛型及类型限定
今天知识星球球友,微信问浪尖了一个spark源码阅读中的类型限定问题.这个在spark源码很多处出现,所以今天浪尖就整理一下scala类型限定的内容.希望对大家有帮助. scala类型参数要点 1. ...
- CentOS7安装Jenkins与配置
安装 将Jenkins存储库添加到yum repos,并从此安装Jenkins. sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenki ...
- HTML学习第二天
HTML学习第二天 今天学的比较少,有些乱,先只写一个知识点 三种样式表插入方式 外部样式表: <link rel="stylesheet" type="text/ ...
- maven项目打包部署到虚拟机测试和生产环境上及查看日志操作
调试通过后提交代码到gitlab,打包部署到相应环境(测试或生产环境)步骤一样1.打包在要打包的项目上右键run as maven clean 清除原来的包,然后run as maven instal ...