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 ...
随机推荐
- 新闻网大数据实时分析可视化系统项目——21、大数据Web可视化分析系统开发
1.基于业务需求的WEB系统设计 2.下载Tomcat并创建Web工程并配置相关服务 下载tomcat,解压并启动tomcat服务. 1)新建web app项目 创建好之后的效果 2)对tomcat进 ...
- PHP代码审计之入门实战
系统介绍 CMS名称:新秀企业网站系统PHP版 官网:www.sinsiu.com 版本:这里国光用的1.0 正式版 (官网最新的版本有毒,网站安装的时候居然默认使用远程数据库???迷之操作 那站长的 ...
- tools.lombok
@Slf4j @Data @Accessors @Builder
- 关于Android 的内存泄露及分析(转)
一. Android的内存机制Android的程序由Java语言编写,所以Android的内存管理与Java的内存管理相似.程序员通过new为对象分配内存,所有对象在java堆内分配空间:然而对象的释 ...
- 深入理解JVM Note
第2章 Java内存区域与内存溢出异常 运行时数据区域 在虚拟机有栈.堆和方法区. 线程共享的:堆.方法区 不共享的:栈.程序计数器(代码执行的行号) 程序计数器(Program Counter Re ...
- 003、Java的单行注释
代码如下: package TIANPAN; public class TestDemo { public static void main(String args[]) { // JAVA的单行注释 ...
- 010-PHP输出数组中第某个元素
<?php $monthName = array(1 => "January", "February", "March",//初 ...
- 编码解码:UrlDecode解码及UrlEncode编码的jQuery方法
找了n多方法,终于找到,不容易. C#:Server.UrlEncode(ur) Jquery解码:decodeURIComponent(url); Jquery编码:encodeURICompone ...
- 一对多关联按照一方的id查找信息的一个笛卡尔积问题
mapper中,关联的一对多,正确的结果应该是按照一方的id查找,根据映射得到的是一个一方对象,对象里嵌套这list属性,但是结果却出来了多条,在sql中实验 一方中123456789只有一条数据 多 ...
- centos-6更新yum源(163)
更新前请先备份原来的repo文件,养成好习惯 cd /etc/yum.repos.d/ mv CentOS-Base.repo CentOS-Base.repo.bak 到http://mirrors ...