【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 ...
随机推荐
- 【Cocos2d-Js基础教学(4)cocostudio在cocos2dx-Js中的使用】
首先我们打开官方网站www.cocos2d-x.org,下载我们安装最新的cocostudio(cocos). 简介: Cocos Studio升级为cocos.更优秀的产品.更优质的服务.游戏开发一 ...
- 【redmine】密码忘了后重新设置
有段时间没有使用,忘记了原来的密码,搜索网上有一篇文章,不过版本比较老,和现在文件位置不一样,参考后成功重置了密码,感谢原作者. 原文内第一步一般是不需要的.主要是用ruby命令修改数据库内容. 进入 ...
- CDN 和 DNS
原文地址:http://www.cnblogs.com/xitang/p/3575255.html 相信有很多的朋友会被这几个名词绕的有些头大,很多朋友觉得智能DNS跟双线加速.CDN加速是类似的技术 ...
- angularjs + seajs构建Web Form前端(一)
简介 Bootstrap是Twitter推出的一个用于前端开发的开源工具包,它由Twitter的设计师Mark Otto和Jacob Thornton合作开,是一个CSS/HTML框架. Angula ...
- css3 keyframes在yuicompressor下压缩问题
@keyframes proBackAction { 0% { opacity:; } 100% { opacity: .8; } } @keyframes proBackAction { 0{ op ...
- MFC ADO连接Oracle12c数据库 服务端配置
要想客户端访问服务器端的oracle数据库的话,还需要服务端设置下监听程序及本地网络服务名配置. 发现百度文库上面有这方面的文档,我就不重复写了.请参照一下网址: http://wenku.baidu ...
- Only top uni produces good ppt.
重要的事说三遍: 学技术,我只相信那几所top高校 学技术,我只相信那几所top高校 学技术,我只相信那几所top高校 <Good Habits you must own> Wake up ...
- Swift_3.0_取消杂乱无章的log输出
一 举例: 输出的杂乱无章的东西 subsystem: com.apple.UIKit, category: HIDEventFiltered, enable_level: , persist_lev ...
- LeetCode-95. Unique Binary Search Trees II
Description: Given n, generate all structurally unique BST's (binary search trees) that store values ...
- LeetCode——Merge k Sorted Lists
Discription: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its ...