POJ 1035-Spell checker(字符串)
题目地址:POJ 1035
题意:输入一部字典。输入若干单词。 若某个单词能在字典中找到,则输出corret。若某个单词能通过 变换 或 删除 或 加入一个字符后。在字典中找得到。则输出这些单词。输出顺序依据 输入的那部字典的字典序;若某个单词不管操作与否都无法在字典中找得到,则输出空。
思路:关于全然匹配的就直接输出就好。解题关键在不全然匹配的情况:比較时我们先算两个单词长度差之差,有三种情况:len1=strlen(str)len2=strlen(mp[n]]
假设len1==len2则是可能有一个字符不一样;逐个字符比較。统计不同字符数
假设len1+1==len2则是少一个字符。逐个字符比較,假设有字符不同。则mp[n]字符下标往下移动一位。str不变,不同字符数加1
假设len1-1==len2则是多一个字符,逐个字符比較。假设有字符不同。则str字符下标往下移动一位。mp[n]不变。不同字符数加1
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <map>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef __int64 LL;
const int inf=0x3f3f3f3f;
const double pi= acos(-1.0);
const double esp=1e-7;
const int maxn=10010;
char mp[maxn][20];
char str[20];
int check(int n)
{
int i,j;
int cnt;
int len1=strlen(str);
int len2=strlen(mp[n]);
if(len1-len2==1) {
cnt=0;
i=j=0;
for(; i<len1;) {
if(str[i]!=mp[n][j]) {
cnt++;
i++;
} else {
i++;
j++;
}
}
if(cnt==1)
return 1;
return 0;
} else if(len1==len2) {
cnt=0;
i=j=0;
for(; i<len1;) {
if(str[i]!=mp[n][j])
cnt++;
i++,j++;
}
if(cnt==1)
return 1;
return 0;
} else if(len1-len2==-1) {
cnt=0;
i=j=0;
for(; j<len2;) {
if(str[i]!=mp[n][j]) {
cnt++;
j++;
} else {
i++;
j++;
}
}
if(cnt==1)
return 1;
return 0;
}
return 0;
}
int main()
{
int n=0,i;
while(~scanf("%s",mp[n])) {
if(mp[n][0]=='#')
break;
n++;
}
while(~scanf("%s",str)) {
if(str[0]=='#')
break;
for(i=0; i<n; i++) {
if(strcmp(str,mp[i])==0) {
printf("%s is correct\n",str);
break;
}
}
if(i==n) {
printf("%s:",str);
for(i=0; i<n; i++)
if(check(i))
printf(" %s",mp[i]);
puts("");
}
}
return 0;
}
POJ 1035-Spell checker(字符串)的更多相关文章
- poj 1035 Spell checker ( 字符串处理 )
Spell checker Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16675 Accepted: 6087 De ...
- POJ 1035 Spell checker 字符串 难度:0
题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...
- 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 ...
- POJ 1035 Spell checker(串)
题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...
- poj 1035 Spell checker(水题)
题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...
- poj 1035 Spell checker(hash)
题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...
- POJ 1035 Spell checker (模拟)
题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...
- POJ 1035 Spell checker 简单字符串匹配
在输入的单词中删除或替换或插入一个字符,看是否在字典中.直接暴力,172ms.. #include <stdio.h> #include <string.h> ]; ][], ...
- POJ1035——Spell checker(字符串处理)
Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...
随机推荐
- 第三方库requests
requests库 # 1.记得安装 第三方 模块 requests # pip install requests import requests url = 'http://www.baidu.co ...
- [agc015c]nuske vs phantom thnook
题意: 有一个n*m的网格图,每个格子是蓝色或白色.四相邻的两个格子连一条边,保证蓝格子构成一个森林. 有q组询问,每次询问给出一个矩形,问矩形内蓝格子组成的联通块个数. $1\leq n,m\leq ...
- 如何使用外部插件picker
近日有需求做一个职业选择弹框,在网上搜了半天也没合适的: 暴躁大佬协助我DIY一个插件,直接使用,顺滑流畅,随心所欲!特别鸣谢@一样菜 不多BB了,直接撸代码: 引用写在上面: /* 更改职业 */ ...
- [TJOI2011]树的序(贪心,笛卡尔树)
[TJOI2011]树的序 题目描述 众所周知,二叉查找树的形态和键值的插入顺序密切相关.准确的讲:1.空树中加入一个键值k,则变为只有一个结点的二叉查找树,此结点的键值即为k:2.在非空树中插入一个 ...
- PID三种参数的理解
来源:http://blog.gkong.com/liaochangchu_117560.ashx PID是比例.积分.微分的简称,PID控制的难点不是编程,而是控制器的参数整定.参数整定的关键是正确 ...
- ASP.NET-本地化、全球化
在<system.web>中加入一个全球化的标识,网站就可以自适应全球化了 也可以将出错信息全球化 上面的这种方式测试过对google浏览器好像没用,但是对IE内核的是可行的,可能goog ...
- Android中处理Touch Icon的方案
苹果的Touch Icon相对我们都比较熟悉,是苹果为了支持网络应用(或者说网页)添加到桌面需要的图标,有了这些Touch Icon的网页链接更加和Native应用更相像了.由于苹果设备IPod,IP ...
- TreeMap集合怎样依照Value进行排序
------- android培训.java培训.期待与您交流! ---------- 我们知道,TreeMap集合是依照Key进行排序的,怎样依照Value进行排序呢?如今有一个TreeMap集合 ...
- 解决The hierarchy of the type is inconsistent错误
可能的原因:自己的类继承于某个类,这个类或者这个类继承的类或者再往上继承的某个类所在的jar包没有被引入. 比如:使用Spring的AOP时,假设须要继承MethodBeforeAdvice和Afte ...
- 物理读之LRU(近期最少被使用)的深入解析
转载请注明出处: http://blog.csdn.net/guoyjoe/article/details/38264883 一组LRU链表包含LRU主链.LRU辅助链.LRUW主链,LRUW辅助链, ...