题意:求子串在文本串中出现了多少次。

解法:使用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)的更多相关文章

  1. POJ 3461 Oulipo[附KMP算法详细流程讲解]

      E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  2. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  3. poj 3461 Oulipo(KMP模板题)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 36903   Accepted: 14898 Descript ...

  4. POJ 3461 Oulipo(KMP裸题)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  5. poj 3461 Oulipo,裸kmp

    传送门 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32373   Accepted: 13093 Desc ...

  6. POJ 3461 Oulipo(——KMP算法)

    Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, without t ...

  7. poj 3461 - Oulipo 经典kmp算法问题

    2017-08-13 19:31:47 writer:pprp 对kmp算法有了大概的了解以后,虽然还不够深入,但是已经可以写出来代码,(可以说是背会了) 所以这道题就作为一个模板,为大家使用吧. 题 ...

  8. poj 3461 Oulipo(kmp统计子串出现次数)

    题意:统计子串出现在主串中的次数 思路:典型kmp #include<iostream> #include<stdio.h> #include<string.h> ...

  9. poj 3461 Oulipo(KMP)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 49378   Accepted: 19617 Descript ...

  10. 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 ...

随机推荐

  1. Unity3D常用代码总结

    1 GUI汇总 function OnGUI() { GUI.Label(Rect(1,1,100,20),"I'm a Label"); //1 GUI.Box(Rect(1,2 ...

  2. [亿能测试_www.gdtesting.com]测试技术资料网盘共享

    [亿能测试_www.gdtesting.com]测试技术资料网盘共享: http://pan.baidu.com/share/home?uk=974090852

  3. Duilib技巧:背景图片平铺

    贴图的描述 方式有两种    // 1.aaa.jpg    // 2.file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0 ...

  4. jquery的ajax提交时loading提示的处理方法

    方法1:使用ajaxStart方法定义一个全局的“加载中...”提示 $(function(){     $("#loading").ajaxStart(function(){   ...

  5. 如何生成ipa文件

    xcode--Product--Archive 弹出Organizer-Archives选择Distribute---Save for EnterPrise or Ad_Hoc Deployment- ...

  6. p2p研究

    p2p网络结构 中央集中式结构 无集中式非结构 混合式以超级节点结构 穿透原理 防火墙为克隆型(cone net),对称型(Symmetric NAT) 只有克隆型才能用打洞方式穿透 开源方案 htt ...

  7. UnWind Segue

    iOS 6 和 Xcode 4.5 中添加了一个新特性叫做“Unwind Segue”. 使用Unwind Segue,可以方便的在Navigation Controller的Controllers之 ...

  8. VirtualBox Bridged 无线网卡

    启动虚拟机后选择右键单击右下角的网络链接图标,  弹出的窗口中选择Bridged Adapter,  wlan0 然后选择OK 查看virtual Box主页面中setting中网络的配置是否和刚才一 ...

  9. 找工作--Java相关

    Hi 各位 首先自我描述一下,80后程序员,现在在做Eclipse插件开发. 求Java相关职位(Java/Swing/Eclipse Plugin/Python etc), 或者Linux下C相关职 ...

  10. java trim

    rim方法一般用来去除空格,但是根据JDK API的说明,该方法并不仅仅是去除空格,它能够去除从编码’\u0000′ 至 ‘\u0020′ 的所有字符. 回车换行也在这20个字符之中,以下是一个示例: ...