题目地址: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(字符串)的更多相关文章

  1. poj 1035 Spell checker ( 字符串处理 )

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16675   Accepted: 6087 De ...

  2. POJ 1035 Spell checker 字符串 难度:0

    题目 http://poj.org/problem?id=1035 题意 字典匹配,单词表共有1e4个单词,单词长度小于15,需要对最多50个单词进行匹配.在匹配时,如果直接匹配可以找到待匹配串,则直 ...

  3. poj 1035 Spell checker

    Spell checker Time Limit: 2000 MS Memory Limit: 65536 KB 64-bit integer IO format: %I64d , %I64u   J ...

  4. [ACM] POJ 1035 Spell checker (单词查找,删除替换添加不论什么一个字母)

    Spell checker Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18693   Accepted: 6844 De ...

  5. POJ 1035 Spell checker(串)

    题目网址:http://poj.org/problem?id=1035 思路: 看到题目第一反应是用LCS ——最长公共子序列 来求解.因为给的字典比较多,最多有1w个,而LCS的算法时间复杂度是O( ...

  6. poj 1035 Spell checker(水题)

    题目:http://poj.org/problem?id=1035 还是暴搜 #include <iostream> #include<cstdio> #include< ...

  7. poj 1035 Spell checker(hash)

    题目链接:http://poj.org/problem?id=1035 思路分析: 1.使用哈希表存储字典 2.对待查找的word在字典中查找,查找成功输出查找成功信息 3.若查找不成功,对word增 ...

  8. POJ 1035 Spell checker (模拟)

    题目链接 Description You, as a member of a development team for a new spell checking program, are to wri ...

  9. POJ 1035 Spell checker 简单字符串匹配

    在输入的单词中删除或替换或插入一个字符,看是否在字典中.直接暴力,172ms.. #include <stdio.h> #include <string.h> ]; ][], ...

  10. POJ1035——Spell checker(字符串处理)

    Spell checker DescriptionYou, as a member of a development team for a new spell checking program, ar ...

随机推荐

  1. php——get与post方法(转)

    file_get_contents版本: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php /**  * 发送p ...

  2. mariadb-增删改查怎么用

    MariaDB 数据类型 MariaDB数据类型可以分为数字,日期和时间以及字符串值. 使用数据类型的原则:够用就行,尽量使用范围小的,而不用大的 常用的数据类型 整数:int, (bit比整数还要小 ...

  3. 紫书 例题 10-2 UVa 12169 (暴力枚举)

    就是暴力枚举a, b然后和题目给的数据比较就ok了. 刘汝佳这道题的讲解有点迷,书上讲有x1和a可以算出x2, 但是很明显x2 = (a * x1 +b) 没有b怎么算x2?然后我就思考了很久,最后去 ...

  4. 紫书 习题 11-10 UVa 12264 (二分答案+最大流)

    书上写的是UVa 12011, 实际上是 12264 参考了https://blog.csdn.net/xl2015190026/article/details/51902823 这道题就是求出一种最 ...

  5. C语言计算字符串数组中每个字符串出现的个数

    unsigned int str_num(char *str[], int num[], int len) { int i, j; int count; int flag[len]; ; i < ...

  6. 2015 Multi-University Training Contest 1 y sequence

    Y sequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. 如何用一次性密码通过 SSH 安全登录 Linux

    有人说,安全不是一个产品,而是一个过程.虽然 SSH 协议被设计成使用加密技术来确保安全,但如果使用不当,别人还是能够破坏你的系统:比如弱密码.密钥泄露.使用过时的 SSH 客户端等,都能引发安全问题 ...

  8. Linux经常使用命令(九) - cat

    cat命令的用途是连接文件或标准输入并打印.这个命令经常使用来显示文件内容,或者将几个文件连接起来显示,或者从标准输入读取内容并显示,它常与重定向符号配合使用. 1. 命令格式: cat [选项] 文 ...

  9. 使用React Hook后的一些体会

    一.前言 距离React Hook发布已经有一段时间了,笔者在之前也一直在等待机会来尝试一下Hook,这个尝试不是像文档中介绍的可以先在已有项目中的小组件和新组件上尝试,而是尝试用Hook的方式构建整 ...

  10. spark pipeline 例子

    """ Pipeline Example. """ # $example on$ from pyspark.ml import Pipeli ...