【poj 3461】Oulipo(字符串--KMP)
题意:求子串在文本串中出现了多少次。
解法:使用KMP的next[ ]和tend[ ]数组计数。
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std; const int N=,M=;
char s[N],ss[M];
int n,m;
int next[N];//,tend[M]; void kmp()
{
memset(next,,sizeof(next));
int p=;
next[]=;
for (int i=;i<=n;i++)
{
while (s[i]!=s[p+] && p) p=next[p];
if (s[i]==s[p+]) p++;
next[i]=p;
}
//memset(tend,0,sizeof(tend));
int cnt=; p=;
for (int i=;i<=m;i++)
{
while (ss[i]!=s[p+] && p) p=next[p];
if (ss[i]==s[p+]) p++;
//tend[i]=p;
if (p==n) cnt++;
}
printf("%d\n",cnt);
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
scanf("%s%s",s+,ss+);
n=strlen(s+),m=strlen(ss+);
kmp();
}
return ;
}
【poj 3461】Oulipo(字符串--KMP)的更多相关文章
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- poj 3461 Oulipo(KMP模板题)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 36903 Accepted: 14898 Descript ...
- POJ 3461 Oulipo(KMP裸题)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- poj 3461 Oulipo,裸kmp
传送门 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32373 Accepted: 13093 Desc ...
- POJ 3461 Oulipo(——KMP算法)
Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...
- poj 3461 - Oulipo 经典kmp算法问题
2017-08-13 19:31:47 writer:pprp 对kmp算法有了大概的了解以后,虽然还不够深入,但是已经可以写出来代码,(可以说是背会了) 所以这道题就作为一个模板,为大家使用吧. 题 ...
- poj 3461 Oulipo(kmp统计子串出现次数)
题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...
- poj 3461 Oulipo(KMP)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 49378 Accepted: 19617 Descript ...
- HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)
HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...
随机推荐
- Embeding Python & Extending Python with FFPython
Introduction ffpython is a C++ lib, which is to simplify tasks that embed Python and extend Python. ...
- solr多核配置
假设已经配置好了一个单core的solr服务器. solr.xml配置文件 单核和多核主要在solr.xml配置不同.在solr/example中已经有一个名称为multicore的文件夹里面给我们配 ...
- Tomcat and solr 环境配置
Tomcat and solr tomcat 安装 下载安装tomcat8.0 http://tomcat.apache.org/download-80.cgi wget http://apache. ...
- KPI绩效考核为何在国内不管用?
很多外国很好的管理制度,到了中国都有水土不服,就像KPI绩效考核一样,到了中国执行得很不好,甚至还不如用本土的人治管理方法,那是为何呢?为什么国内学平衡计分法和KPI的热情非常高,效果却往往有限? 其 ...
- Equals Finalize GetHashCode GetType MemberwiseClone ReferenceEquals ToString String.IsInterned
参考资料: http://blog.csdn.net/afgasdg/article/details/6889383 http://www.cnblogs.com/skyivben/archive/2 ...
- 一张Windows版本发展图——纪念XP服役13你年
88年的人,接触PC十几年.第一次真正开始学习PC是在小学四年级的电脑兴趣班上,那时候好多事情还历历在目.那些年,神秘的DOS,向里面输入一些自己都不懂得命令,出现的场景让一个少年内心砰砰直跳.一个& ...
- [论文笔记] 一种Java遗留系统服务化切分和封装方法 (计算机学报, 2009)
李翔,怀进鹏,曾晋,高鹏. 一种Java遗留系统服务化切分和封装方法. 计算机学报, 32(9), 2009, p1084-1815 (gs:5) 1. 本文研究从Java遗留系统中切分并封装出Web ...
- ExtJS远程数据-本地分页
背景 一般情况下,分页展示是前端只负责展示,后台通过SQL语句实现分页查询.当总数据量在千条以下,适合一次性查询出符合条件的所有数据,让前端页面负责分页也是一种选择. 实例 现通过ExtJS 4扩展类 ...
- MySql 数据操作类
/// <summary> /// MySqlHelper 的摘要说明. /// </summary> public class MySqlHelper { public st ...
- WPF之DataGrid
1.WPF 4 DataGrid 控件(基本功能篇) 基本使用,绑定数据展示 2.WPF 4 DataGrid 控件(自定义样式篇) 定义行,列,头,单元格等样式 3.WPF 4 DataGrid 控 ...