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 ...
随机推荐
- Mysqli基础知识
相信原来在开始学习php的时候,很多人使用的数据库首选MySQL,连接数据库的扩展首选mysql扩展,但随着php版本的提高,mysql扩展正逐渐被mysqli和PDO所取代.正如使用mysql函数时 ...
- 大数据:从开源告诉你身边的IT故事
最近我们Team利用Dream分布式计算平台,做了这样一件事情,将Github的大量数据通过爬虫抓取下来,通过分析后,我们抽取最近一年中部分的开发者和项目信息,得到了如下有趣的信息,故分享之,数据原汁 ...
- 茗洋Easy UI 1.3.2 部分问题解决系列专题[Combo模糊匹配中文问题 修复]
本次给大家带来的EasyUI的我研究拓展的新特性 我使用的是 EasyUI 1.3.2版本的,项目是ASP.NET MVC3,但是本篇讲解用不上ASP.NET MVC,仅仅修改官方Demo你就知道怎 ...
- Javascript的io操作
一.功能实现核心:FileSystemObject 对象 要在javascript中实现文件操作功能,主要就是依靠FileSystemobject对象. 二.FileSystemObject编程 使用 ...
- 每天一个linux命令(15):whereis 命令
whereis命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s).如果省略参数,则返回所有信息. 和 find相比,whereis查找的速度 ...
- chromiun 学习《一》
众所周知,Chrome是建立在开源的Chromium项目上的. 而且不得不说,学习并分析开源项目的代码对一个程序员的提高确实蛮大的.这篇博文我会记录一下学习过程中我遇到的一些问题,并分享学习中我所参考 ...
- .net架构设计读书笔记--第三章 第8节 域模型简介(Introducing Domain Model)
一.数据--行为转变 很长的时间,典型的分析方法或多或少是以下两种,第一,收集需求并做一些分析,找出有关实体 (例如,客户. 订单. 产品) 和进程来实现. 第二,手持这种理解你尝试推断一个物 ...
- knockout_主页的demo复习
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- Js-字符转换数字
s 字符串转化成数字 的 三种方法主要有 转换函数.强制类型转换.利用js变量弱类型转换. 1. 转换函数: js提供了parseInt()和parseFloat()两个转换函数.前者把值转换成整数, ...
- 【探秘ES6】系列专栏(一):ES6简介
摘要:新一代JavaScript标准,ES6即将发布.[探秘ES6]系列专栏将一一剖析ES6的诸多新特性,让Web开发者对此有清晰全面的了解.本文为系列的第一篇,带你了解ES6到底是什么以及有哪些令人 ...