poj 1035 <set + 指针移动 解决 单词检测>
来源:互联网 发布:magento2 cms block 编辑:程序博客网 时间:2024/06/06 00:04
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
iishashavebemymorecontestmetooifaward#meawaremcontesthavooorifimre#
Sample Output
me is correctaware: awardm: i my mecontest is correcthav: has haveoo: tooor:i is correctfi: imre: more me
Source
看学长写的好嗨皮----学长博客
题意:
先给出一个字典,然后输入单词--让你判断这个单词在字典中是否存在--不存在时看是否可以通过换一个字符--或增一个字符--或减一个字符来得到一个单词
set + 指针的移动来解决这个真的好溜---
#include <set>
如:set<int,less<int> > set1;
less<int>是一个标准类,用于形成升序排列函数对象。降序排列是用greater<int>。
begin() 返回指向第一个元素的迭代器
clear() 清除所有元素
count() 返回某个值元素的个数
empty() 如果集合为空,返回true(真)
end() 返回指向最后一个元素之后的迭代器,不是最后一个元素
equal_range() 返回集合中与给定值相等的上下限的两个迭代器
erase() 删除集合中的元素
find() 返回一个指向被查找到元素的迭代器,如果没找到则返回end()
get_allocator() 返回集合的分配器
insert() 在集合中插入元素
lower_bound() 返回指向大于(或等于)某值的第一个元素的迭代器
key_comp() 返回一个用于元素间值比较的函数
max_size() 返回集合能容纳的元素的最大限值
rbegin() 返回指向集合中最后一个元素的反向迭代器
rend() 返回指向集合中第一个元素的反向迭代器
size() 集合中元素的数目
swap() 交换两个集合变量
upper_bound() 返回大于某个值元素的迭代器
value_comp() 返回一个用于比较元素间的值的函数
代码:
#include<cstring>#include<iostream>#include<string>#include<cstdio>#include<set>#include<algorithm>using namespace std;struct node{int len;char ch[25];}trie[10010];int xxx[3]={0,1,1};int yyy[3]={1,0,1};int find(char xx[],char yy[]){int lx=strlen(xx);int ly=strlen(yy);int aa=lx-ly;if (aa<-1||aa>1)return 0;int x=0,y=0;for (;x<lx&&y<ly&&xx[x]==yy[y];)x++,y++;for (int i=0;i<3;i++)//替换--增--减-- {int xl=x+xxx[i];int yl=y+yyy[i];if (strcmp(xx+xl,yy+yl)==0) return 1;}return 0;}int main(){set <string> slo;int kp=0;while (gets(trie[kp].ch)){if (trie[kp].ch[0]=='#')break;slo.insert(trie[kp].ch);trie[kp].len=strlen(trie[kp].ch);kp++;}char ko[25];while (gets(ko)){if (ko[0]=='#')break;if (slo.count(ko))printf("%s is correct\n",ko);else{printf("%s:",ko);for (int i=0;i<kp;i++)if (find(ko,trie[i].ch))printf(" %s",trie[i].ch);printf("\n");}}return 0;}
- poj 1035 <set + 指针移动 解决 单词检测>
- 单词数set<string>
- set与单词数
- POJ 1035 Spell checker 查找单词
- iTerm2设置单词移动
- 解决鼠标指针移动时出现停顿卡的原因
- 解决鼠标指针移动时出现停顿卡的原因
- 解决鼠标指针移动时出现停顿卡的原因
- 解决鼠标指针移动时出现停顿卡的原因
- HDOJ 2072 单词数 (set)
- hdu 单词数 (set)
- POJ-2503-查单词
- POJ 4104:单词翻转
- 一个移动检测 demo
- 移动目标检测
- Unity解决物体移动速度过快而导致不能检测到碰撞的问题
- HDU2072 单词数 解题报告--set
- 单词数 (STL set集合)
- Retrofit初探和简单使用
- 【mysql】mysql数据库常用命令
- 邮箱不可用 550 User has no permission
- Java 打印输出及简单运算
- jdk详解
- poj 1035 <set + 指针移动 解决 单词检测>
- Mysql常用命令详解
- 2016太原网络营销师解说怎样让产品盈利,你知道吗?
- NodeJS学习笔记之FS文件模块
- 矩阵快速幂
- Js中call、apply的用法及拓展
- linux命令执行后的 返回值与错误代码
- MySQL创建用户与授权
- java中的char类型