Description

在信息检索系统中一个很重要的环节就是关键字符串的查找,从而很多对自己有用的信息。给你一个很长的一段文字, 和一个关键信息字符串,现在要你判断这段文字里面是否有关键字符串。

Input

输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一段文字(中间不含空格,长度不超过1000),和一个关键信息字符串(长度不超过10)

Output

输出这段文字里面是否有关键字符串,如果有则输出Yes,否者输入No,具体细节见样例。

Sample Input

3
songpanda pan
hudzpdgj huz
aabdcc ad

Sample Output

Case #1: Yes
Case #2: No
Case #3: No
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int next[];
char str1[],str2[];
int n; void get_next(int len2)//生成next数组
{
int i = ,j = -;
next[] = -;
while (i<len2)
{
if(j == - || str2[i] == str2[j])
{
i++;
j++;
if (str2[i]!=str2[j])
next[i] = j;
else
next[i] = next[j];
}
else
j = next[j];
}
} int kmp(int len1,int len2)
{
int i=,j=;
get_next(len2);
while(i<len1)
{
if(j==-||str1[i]==str2[j])
{
i++;j++;
}
else
j=next[j];
if(j==len2)
{
return ;
}
}
} int main()
{
int kase=,k;
cin>>n;
getchar();
while(n--)
{
k=;
cin>>str1>>str2;
get_next(strlen(str2));
k=kmp(strlen(str1),strlen(str2));
if(k==)
printf("Case #%d: Yes\n",kase);
else
printf("Case #%d: No\n",kase);
kase++;
}
return ;
}

nefu 197 关键字检索(kmp算法)的更多相关文章

  1. 【★】KMP算法完整教程

    KMP算法完整教程 全称:                               Knuth_Morris_Pratt Algorithm(KMP算法) 类型:                 ...

  2. 【★】KMP算法完整教程

    KMP算法完整教程 全称:                               Knuth_Morris_Pratt Algorithm(KMP算法) 类型:                 ...

  3. KMP算法完整教程 (上)

    KMP算法完整教程 全称: Knuth_Morris_Pratt Algorithm(KMP算法) 类型: 高级检索算法 功能: 字符串匹配查找 提出者: D.E.Knuth(克努兹),J.H.Mor ...

  4. !KMP算法完整教程

      KMP算法完整教程 全称:                               Knuth_Morris_Pratt Algorithm(KMP算法) 类型:                ...

  5. 算法:KMP算法

    算法:KMP排序 算法分析 KMP算法是一种快速的模式匹配算法.KMP是三位大师:D.E.Knuth.J.H.Morris和V.R.Pratt同时发现的,所以取首字母组成KMP. 少部分图片来自孤~影 ...

  6. (原创)详解KMP算法

    KMP算法应该是每一本<数据结构>书都会讲的,算是知名度最高的算法之一了,但很可惜,我大二那年压根就没看懂过~~~ 之后也在很多地方也都经常看到讲解KMP算法的文章,看久了好像也知道是怎么 ...

  7. KMP算法的Next数组详解

    转载请注明来源,并包含相关链接. 网上有很多讲解KMP算法的博客,我就不浪费时间再写一份了.直接推荐一个当初我入门时看的博客吧:http://www.cnblogs.com/yjiyjige/p/32 ...

  8. 【转】KMP算法

    转载请注明来源,并包含相关链接.http://www.cnblogs.com/yjiyjige/p/3263858.html 网上有很多讲解KMP算法的博客,我就不浪费时间再写一份了.直接推荐一个当初 ...

  9. 详解KMP算法

    转载注明出处:http://www.cnblogs.com/yjiyjige/p/3263858.html 什么是KMP算法: KMP是三位大牛:D.E.Knuth.J.H.Morris和V.R.Pr ...

随机推荐

  1. OpenCV程序在Debug时出现「PDB文件无法加载」的一个解决方法

    这几天毕设要用到OpenCV,按照网上的教程来搭建开发环境. 用的是OpenCV 3.0 beta + Visual Studio Community 2013.我的系统64位是Win 8.1,但在加 ...

  2. Salesforce apex标签的有关内容

    局部刷新标签: apex:actionSupport event="onchange" action="{!changeSelect}" rerender=&q ...

  3. Zend Studio 无法打开的解决办法

    今天郁闷的...正在写代码,突然 computer 嗝屁了,断电后自动重启了一次,开机后就悲剧了,Zend Studio 9 无法打开了,每次运行只弹窗个 请查看项目错误日志的提示 然后就没反应了.. ...

  4. sqlalchemy 映射的小例子

    1.多张表映射到一个类 import pandas as pdfrom settings import DATABASESfrom sqlalchemy import create_engineimp ...

  5. HDU 1896 Stones (优先队列)

    Problem Description Because of the wrong status of the bicycle, Sempr begin to walk east to west eve ...

  6. POJ 2599 A funny game#树形SG(DFS实现)

    http://poj.org/problem?id=2599 #include<iostream> #include<cstdio> #include<cstring&g ...

  7. POJ 1862 Stripies#贪心(水)

    (- ̄▽ ̄)-* #include<iostream> #include<cstdio> #include<cmath> #include<algorithm ...

  8. C# Monads的实现(二)

    再谈continuation monad 上一篇中我们已经介绍了continuation monad,但是这个monad与Identity,Maybe,IEnumerable monads稍微难于理解 ...

  9. Leetcode 39 40 216 Combination Sum I II III

    Combination Sum Given a set of candidate numbers (C) and a target number (T), find all unique combin ...

  10. 洛谷-小鱼会有危险吗-BOSS战-入门综合练习2

    题目描述 Description 有一次,小鱼要从A处沿直线往右边游,小鱼第一秒可以游7米,从第二秒开始每秒游的距离只有前一秒的98%.有个极其邪恶的猎人在距离A处右边s米的地方,安装了一个隐蔽的探测 ...