题意:给定一篇文章和一些句子。询问句子是否在文章中出现。

kmp模板题

 /*
kmp
*/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<math.h>
using namespace std;
typedef long long int64;
//typedef __int64 int64;
typedef pair<int64,int64> PII;
#define MP(a,b) make_pair((a),(b))
const int maxn = ;
const int maxm = ;
const int inf = 0x7fffffff;
const double pi=acos(-1.0);
const double eps = 1e-; char text[ maxn ][ maxm ];
int len_text;
char pat[ maxn ][ maxm ];
int len_pat;
int next[ maxn ]; void getnext(){
int i,j;
next[ ] = -;
i = ;
j = -;
while( i<len_pat ){
if( j==-||strcmp( pat[i],pat[j] )==||strcmp( pat[j],"_" )==||strcmp( pat[i],"_" )== ){
i ++ ;
j ++ ;
next[ i ] = j;
}
else
j = next[ j ];
}
return ;
} bool kmp( ){
getnext();
//for( int i=0;i<len_pat;i++ ){
// printf("next[ %d ] = %d \n",i,next[i]);
//}
int i,j;
i = ;
j = ;
while( i<len_text&&j<len_pat ){
if( j==-||strcmp( text[i],pat[j] )==||strcmp(pat[j],"_")== ){
i ++ ;
j ++ ;
}
else
j = next[j];
if( j==len_pat ) return true;
}
return false;
} int main(){
int T;
scanf("%d",&T);
int Case = ;
while( T-- ){
len_text = ;
while( ){
scanf("%s",text[ len_text ]);
if( strcmp( text[ len_text ],"@" )== ){
break;
}
len_text ++ ;
}//input the passage
int m;
scanf("%d",&m);
printf("Case %d:\n",Case++);
while( m-- ){
len_pat = ;
while( ){
scanf("%s",pat[ len_pat ]);
if( strcmp( pat[ len_pat ],"@" )== ){
break;
}
len_pat ++ ;
}
bool flag = kmp();
if( flag ) puts("YES");
else puts("NO");
}
}
return ;
}

FZU-1926+KMP的更多相关文章

  1. fzu Problem 2128 最长子串(KMP + strstr 经典好题)

     Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长.  Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...

  2. FZU 2122 ——又见LKity——————【KMP字符串匹配】

    Problem 2122 又见LKity Accept: 413    Submit: 1425Time Limit: 1000 mSec    Memory Limit : 32768 KB  Pr ...

  3. FZU 2122 又见LKity(KMP+返回所有匹配位置)

    基础kmp应用,找到所有匹配位置即可 #include<stdio.h> #include<string.h> #include<algorithm> #inclu ...

  4. FZU - 1901 Period II(kmp所有循环节)

    Problem Description For each prefix with length P of a given string S,if S[i]=S[i+P] for i in [0..SI ...

  5. (KMP Next的运用) Period II -- fzu -- 1901

    http://acm.fzu.edu.cn/problem.php?pid=1901 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=703 ...

  6. FZU 1901 Period II(KMP循环节+公共前后缀)

    题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要 ...

  7. Period II FZU - 1901(拓展kmp)

    拓展kmp板题 emm...我比较懒 最后一个字母进了vector两个1  不想改了...就加了个去重... 哈哈 #include <iostream> #include <cst ...

  8. fzu Problem 2275 Game(kmp)

    Problem 2275 Game Accept: 62    Submit: 165Time Limit: 1000 mSec    Memory Limit : 262144 KB  Proble ...

  9. FZU 2122 又见LKity【字符串/正难则反/KMP/把一个字符串中某个部分替换为另一个部分】

    嗨!大家好,在TempleRun中大家都认识我了吧.我是又笨又穷的猫猫LKity.很高兴这次又与各位FZU的ACMer见面了.最近见到FZU的各位ACMer都在刻苦地集训,整天在日光浴中闲得发慌的我压 ...

  10. Fzu Problem 1901 Period II (kmp)

    题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...

随机推荐

  1. C#学习笔记之线程 - 高级主题:非阻塞同步

    非阻塞同步 - Nonblock Synchronization 前面提到,即使在简单的赋值和增加一个字段的情况下也需要处理同步.尽管,使用锁可以完成这个功能,但是锁必定会阻塞线程,需要线程切换,在高 ...

  2. JavaScript学习笔记(10)——JavaScript语法之操作DOM

    1.页面输出用document.write()方法,但是不可以在window.onload中用,否则整个html页面将被覆盖. 2.通过javascript获取对象后,改变对象中的html内容:doc ...

  3. [Bootstrap]全局样式(一)

    页面必须设置为html5文档类型 <!DOCTYPE html> <html lang="zh-CN"> ... </html> 适应移动设备 ...

  4. 119. Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  5. Linux C 程序 文件操作(Linux系统编程)(14)

    文件操作(Linux系统编程) 创建一个目录时,系统会自动创建两个目录.和.. C语言实现权限控制函数 #include<stdio.h> #include<stdlib.h> ...

  6. 【Sqlserver】修改数据库表中的数据:对缺失的数据根据已有的数据进行修补

    1 --查询时间范围内的数据 select * from dbo.point where wtime >'2014-05-01 23:59:59' and wtime< '2014-05- ...

  7. C#使用Zxing2.0生成二维码 带简单中心LOGO

    参考:http://www.open-open.com/lib/view/open1379214678162.html 代码:http://files.cnblogs.com/halo/%E4%BA% ...

  8. js判断IE6(推荐方法一)

    不得不使用判断的方法 //方法1:推荐 if ( /MSIE 6/.test(navigator.userAgent)){ } //方法2: if ( navigator.appVersion.ind ...

  9. html5实现渐变效果

    <canvas id='test01'></canvas> <script> function draw25(id) { var canvas = document ...

  10. Node.js 【CORS(cross origin resource sharing) on ExpressJS之笔记】

    app.use(function(req, res, next) { res.header("Access-Control-Allow-Origin", "*" ...