FZU-1926+KMP
题意:给定一篇文章和一些句子。询问句子是否在文章中出现。
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的更多相关文章
- fzu Problem 2128 最长子串(KMP + strstr 经典好题)
Problem Description 问题很简单,给你一个字符串s,问s的子串中不包含s1,s2...sn的最长串有多长. Input 输入包含多组数据.第一行为字符串s,字符串s的长度1到10 ...
- FZU 2122 ——又见LKity——————【KMP字符串匹配】
Problem 2122 又见LKity Accept: 413 Submit: 1425Time Limit: 1000 mSec Memory Limit : 32768 KB Pr ...
- FZU 2122 又见LKity(KMP+返回所有匹配位置)
基础kmp应用,找到所有匹配位置即可 #include<stdio.h> #include<string.h> #include<algorithm> #inclu ...
- 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 ...
- (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 ...
- FZU 1901 Period II(KMP循环节+公共前后缀)
题目链接:http://acm.fzu.edu.cn/problem.php?pid=1901 题目大意:题目大意求出所有p满足s[i]=s[i+p](i<=len-p) 解题思路: 其实就是要 ...
- Period II FZU - 1901(拓展kmp)
拓展kmp板题 emm...我比较懒 最后一个字母进了vector两个1 不想改了...就加了个去重... 哈哈 #include <iostream> #include <cst ...
- fzu Problem 2275 Game(kmp)
Problem 2275 Game Accept: 62 Submit: 165Time Limit: 1000 mSec Memory Limit : 262144 KB Proble ...
- FZU 2122 又见LKity【字符串/正难则反/KMP/把一个字符串中某个部分替换为另一个部分】
嗨!大家好,在TempleRun中大家都认识我了吧.我是又笨又穷的猫猫LKity.很高兴这次又与各位FZU的ACMer见面了.最近见到FZU的各位ACMer都在刻苦地集训,整天在日光浴中闲得发慌的我压 ...
- Fzu Problem 1901 Period II (kmp)
题目链接: Problem 1901 Period II 题目描述: 给出一个串,满足长度为p的前缀和长度为p的后缀相等的p的个数,输出p的个数,和p分别是多少? 解题思路: 对kmp的next数组的 ...
随机推荐
- SQLite的简单应用
安装部署 1)进入 SQL 下载页面:http://www.sqlite.org/download.html 2)下载预编译二进制文件包. Windows 环境的如下: 下载完之后,就算部署完成.(P ...
- WCF学习笔记 -- 基本概念
WCF是实现WebService的一种微软提出的技术,整合了.Remote, .NET及ASP.NET服务的一种框架.是Windows Communication Foundation的缩写.WebS ...
- javascript笔记——jqGrid 格式化时间列
{ name:'startTime', sortable:false, editable:true, width:300, sorttype:'date', //unformat:startTime, ...
- 方法:查询MongoDB数据库中最新一条数据(JAVA)
使用JAVA语言查询MongoDB中某个数据库某个集合的最新一条数据: MongoCollection<Document> cpu = MongoClient.getDatabase(&q ...
- spring aop配置及用例说明(2)
欢迎交流转载:http://www.cnblogs.com/shizhongtao/p/3473362.html 这里先介绍下几个annotation的含义, @Before:表示在切入点之前执行. ...
- UVALive 2889(回文数字)
题意:给定i,输出第i个回文数字. 分析:1,2,3,4,……,9------------------------------------------------------------------- ...
- DEDECMS中,获取面包屑导航
获取面包屑导航 {dede:field name='position'/} {dede:field.position/}
- VB.NET转C#代码的工具
比如VB.NET的代码: For Each prop In entity.Details.Properties.All(). OfType(Of Microsoft.LightSwitch.Detai ...
- SharedPreference 的存取
1.通过名称来获取指定的SharedPreferences,下面这句代码表示获取名字问hello的SharedPreferences,数据保存在 data/data/package名/shared_p ...
- php Zend Opcache,xcache,eAccelerator缓存优化详解及对比
XCACHE XCache 是一个开源的 opcode 缓存器/优化器, 这意味着他能够提高您服务器上的 PHP 性能. 他通过把编译 PHP 后的数据缓冲到共享内存从而避免重复的编译过程, 能够直接 ...