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 ...
随机推荐
- 关于RoI pooling 层
ROIs Pooling顾名思义,是pooling层的一种,而且是针对ROIs的pooling: 整个 ROI 的过程,就是将这些 proposal 抠出来的过程,得到大小统一的 feature ma ...
- asp.net core 与EFcore 入门
什么是EFcore? Entity Framework (EF) Core 是轻量化.可扩展和跨平台版的常用 Entity Framework 数据访问技术,EF Core 可用作对象关系映射程序 ( ...
- 洛谷 P1983 车站分级 拓扑排序
Code: #include<cstdio> #include<queue> #include<algorithm> #include<cstring> ...
- PHP十六个魔术方法
PHP中把以两个下划线__开头的方法称为魔术方法(Magic methods),这些方法在PHP中充当了举足轻重的作用. 魔术方法包括: __construct(),类的构造函数 __destruct ...
- How Javascript works (Javascript工作原理) (十) 使用 MutationObserver 监测 DOM 变化
个人总结: 这篇文章介绍了几种监测DOM变化的方法,重点介绍的是一个新浏览器API叫做MutationObserver. 注意:不要和Vue.js种 Object.defineProperty() 的 ...
- 物理机安装CentOS7
最近捯饬到一台很老的机器,装Win7吧卡的不要不要的,思来想去的,搞个CentOS来玩玩,玩玩python的一些个人项目,一般装机啥的,都要做启动盘啥的,但是,这个都的话有很多网友已经分享了很多好的文 ...
- Linux 文件系统挂载
文件系统挂载简介 磁盘分区和格式化完成后,磁盘分区要想能够使用,就需要挂载,在挂载某个分区前需要先建立一个挂载点 挂载:将新的文件系统关联至当前根文件系统 卸载:将某文件系统与当前根文件系统的关 ...
- harbor 安装过程
[root@master01 harbor]# ./prepare Clearing the configuration file: ./common/config/adminserver/env ...
- linux 系统相关命令
说明:此篇以 Debian ( ubuntu16.04 ) 命令为例 1. tab键默认是不能自动补全命令 apt install bash-completion // 安装完成之后重启系统 2. 虚 ...
- 【BZOJ 1296】 [SCOI2009]粉刷匠
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] f[i][j][k]表示第i行前j列刷了k次,最大满意度 f[][j][k]=max{f[i][l][k],f[i][l][k-1] ...