http://acm.hdu.edu.cn/showproblem.php?pid=1686

题意:给定一个文本串和给定一个模式串,求文本串中有几个模式串。

思路:直接套用KMP模板。

 #include<iostream>
#include<cstring>
#include<string>
using namespace std; const int maxn = + ; int next[], n, m;
char text[maxn], pattern[]; void get_next()
{
int i, j;
i = -;
j = ;
::next[] = -;
while (j<m)
{
if (i == - || pattern[i] == pattern[j])
{
::next[++j] = ++i;
}
else
i = ::next[i];
}
} int KMP()
{
int i, j, count = ;
i = j = ;
get_next();
while (i<n)
{
if (j == - || text[i] == pattern[j])
{
i++;
j++;
if (j == m) count++;
}
else
j = ::next[j];
}
return count;
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int t, ans;
cin >> t;
getchar();
while (t--)
{
scanf("%s", pattern);
scanf("%s", text);
n = strlen(text);
m = strlen(pattern);
ans = KMP();
cout << ans << endl;
}
return ;
}

HDU 1686 Oulippo的更多相关文章

  1. hdu 1686 KMP模板

    // hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...

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

  3. HDU - 1686 Oulipo KMP匹配运用

    id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - ...

  4. hdu 1686 Oulipo KMP匹配次数统计

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...

  5. hdu 1686 & poj 2406 & poj 2752 (KMP入门三弹连发)

    首先第一题 戳我穿越;http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意好理解,每组输入一个子串和一个母串,问在母串中有多少个子串? 文明人不要暴力 ...

  6. HDU 1686 - Oulipo - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...

  7. HDU 1686 Oulipo(KMP变形求子串出现数目(可重))

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给两个字符串A,B求出A中出现了几次B(计算重复部分). 解题思路:稍微对kmp()函 ...

  8. hdu 1686 Oulipo kmp算法

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目: Problem Description The French author George ...

  9. hdu 1686 Oulipo (kmp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...

随机推荐

  1. 图片预览-兼容IE

    直接贴代码吧: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  2. 使用SolrJ代码导入,发布搜索服务

    搭建solr服务器:http://www.cnblogs.com/liyafei/p/8005571.html 一导入要搜索的字段 1:确定发布搜索的字段,sql语句 SELECT a.id, b.  ...

  3. logstash的各个场景应用(配置文件均已实践过)

    场景: 1) datasource->logstash->elasticsearch->kibana 2) datasource->filebeat->logstash- ...

  4. mybatis中使用where in查询时的注意事项

    我使用的时候collection值为mapper的参数名如:int deleteRoleByUserIds(@Param("userIds") String[] userIds); ...

  5. 记两个国外CTF的弱pwn

    两道题都来自CSAW CTF 18.PWN学得不够多,如果哪里错了,欢迎留言交流. 第一个题 get_it checksec检查之后,发现栈保护没开,很可能是栈溢出.IDA打开F5看伪源码. int ...

  6. mui笔记

    1.关闭当前页面执行上一个页面的方法 var preview = plus.webview.currentWebview().opener() //获取当前窗口的创建者,即A preview.eval ...

  7. vb6.0的安装

    vb6.0古老的编程软件

  8. Linux服务器配置---ftp限制带宽

    限制带宽 ftp服务器可以设置每个用户的带宽,这样根据实际需求来分配,更加充分的利用系统资源.带宽通过参数“anon_max_rate“和”local_max_rate“来设置,这两个参数在配置文件中 ...

  9. JS重要的内置对象

    Array对象: 属性: .length      获得数组的长度: 方法: .concat() 连接内容或者数组,组成新的数组: .join(n)  用n连接数组的每一项组成字符串,可以是空字符串: ...

  10. Js基础知识6-JavaScript匿名函数和闭包

    匿名函数 1,把匿名函数赋值给变量 var test = function() { return 'guoyu'; }; alert(test);//test是个函数 alert(test()); 2 ...