Spell checker(暴力)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 20188 | Accepted: 7404 |
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
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
Source
#include<stdio.h>
#include<string.h>
char st[][] ;
struct word_check
{
char src[] ;
bool flag ;
int cnt , no[] ;
}word[]; int k , f; void check ()
{
int diff ;
int ans ;
for (int i = ; i < f ; i++)
for (int j = ; j < k ; j++)
if (strcmp (word[i].src , st[j]) == ) {
word[i].flag = ;
} for (int i = ; i < f ; i++)
if (!word[i].flag)
for (int j = ; j < k ; j++) {
diff = strlen (word[i].src) - strlen (st[j]) ;
if (diff == ) {
ans = ;
for (int l = ; st[j][l] != '\0' ; l++) {
if (st[j][l] != word[i].src[l])
ans ++ ;
if (ans > )
break ;
}
if (ans == ) {
word[i].no [word[i].cnt] = j ;
word[i].cnt ++ ;
}
}
else if (diff == ) {
int a = ;
ans = ;
for (int l = ; word[i].src[l] != '\0' ; l++ , a++) {
if (st[j][a] != word[i].src[l]) {
ans ++ ;
a-- ;
}
if (ans > )
break ;
}
if (ans == ) {
word[i].no[word[i].cnt] = j ;
word[i].cnt ++ ;
}
}
else if (diff == -) {
int a = ;
ans = ;
for (int l = ; st[j][a] != '\0' ; l++ , a++) {
if (st[j][a] != word[i].src[l]) {
ans ++ ;
l-- ;
}
if (ans > )
break ;
}
if (ans == ) {
word[i].no[word[i].cnt] = j ;
word[i].cnt ++ ;
}
}
} for (int i = ; i < f ; i++) {
if (word[i].flag) {
printf ("%s is correct\n" , word[i].src) ;
}
else {
printf ("%s:" , word[i].src) ;
for (int j = ; j < word[i].cnt ; j++) {
printf (" %s" , st[word[i].no[j]]) ; }
//printf ("%d\n" , word[i].cnt) ;
printf ("\n") ;
}
}
} int main ()
{
// freopen ("a.txt" , "r" , stdin) ;
while (~ scanf ("%s" , st[])) {
k = ;
f = ;
getchar () ;
while () {
gets (st[++k]) ;
if (strcmp (st[k] , "#") == )
break ;
}
while () {
gets (word[f].src) ;
word[f].cnt = ;
f++ ;
if (strcmp (word[f - ].src , "#") == )
break ;
}
f-- ;
/* for (int i = 0 ; i < k ; i++)
printf ("%d " , word[i].flag) ;
puts ("");
for (int i = 0 ; i < f ; i++)
puts (word[i].src) ;*/
check () ;
}
return ;
}
Spell checker(暴力)的更多相关文章
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- Spell checker
Spell checker Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Subm ...
- poj 1035 Spell checker
Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u J ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
- [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
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 22574 Accepted: 8231 De ...
- Code Spell Checker & VSCode 单词拼写验证
Code Spell Checker & VSCode 单词拼写验证 https://marketplace.visualstudio.com/items?itemName=streetsid ...
- VSCode中插件Code Spell Checker
说在前面 介绍 Code Spell Checker 是在VSCode中的一款插件,能够帮助我们检查单词拼写是否出现错误,检查的规则遵循 camelCase (驼峰拼写法). 安装方法 打开VSCod ...
随机推荐
- 需要中文版《The Scheme Programming Language》的朋友可以在此留言(内附一小段译文)
首先给出原著的链接:http://www.scheme.com/tspl4/. 我正在持续翻译这本书,大概每天都会翻译两小时.若我个人拿不准的地方,我会附上原文,防止误导:还有些不适合翻译的术语,我会 ...
- 数据结构之链表C语言实现以及使用场景分析
牢骚:本篇博客两个星期前已经存为草稿,鉴于发生一些糟糕的事情,今天才基本完成.本人6月份应届毕业生一枚,毕业后当天来到帝都,之后也非常顺利,面试了俩家公司都成功了.一家做C++方面电商ERP,一家做w ...
- 云计算之路-阿里云上:2014年6月12日14:40出现CPU 100%
这是今天遇到的第2次故障,主站1台云服务器在14:40:33-14:41:09期间出现CPU突然跑满的状况,而CPU跑满之前,请求量并没有明显增长. 向阿里云提交之后,说晚上会对这台云服务器的虚拟机进 ...
- SQL Server 收缩日志
一. SQL Server 2008 收缩日志 (1) 使用SQL管理器收缩日志 第一步执行如下命令 ALTER DATABASE platform SET RECOVERY SIMPLE GO 第二 ...
- css为什么要用悬浮
如果这个100px的宽度是一个Img,横内元素.右边也是横内元素的话和块级元素是不同的. 2.文字环绕图片. div下有个img然后有个span标签 img最好悬浮,悬浮虽然说脱离文档,但是还是占空间 ...
- 线段树好题(2004集训队林涛PPT中的3题)
1.snake:主要是要意识到全局的可能连法只有一种= =(略坑,题目的最小长度是唬人的……),所以关键就是能否构造出符合题意的图,可以考虑搜索解决,搜出一个就OK了,但是会发现那些满足条件中线段在非 ...
- 开放封闭原则(OCP,Open Closed Principle)
tks:http://www.cnblogs.com/Benjamin/p/3251987.html
- c# JD快速搜索工具,2015分析JD搜索报文,模拟请求搜索数据,快速定位宝贝排行位置。
分析JD搜索报文 搜索关键字 女装 第二页,分2次加载. rt=1&stop=1&click=&psort=&page=3http://search.jd.com/Se ...
- Android开发环境的调研
在大二下,由于课程需要,就去自学Java,当时就借了一本java面向对象的书来看,根据书上的说明搭建环境,下载了JDK1.6和eclipse.但从来没有用过eclipse,java也就只是刚入门而已. ...
- 团队作业--Beta版本冲刺
项目冲刺随笔 第一天 第二天 第三天 第四天 第五天 第六天 第七天