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. ext3日志模式

    ext3日志模式 http://blog.sina.com.cn/s/blog_5d4ab4b40100dosx.html ext3支持多种日志模式 ext3 是ext2文件系统的高一级版本,完全兼容 ...

  2. [py][mx]django课程页显示city和机构封面图

    city和课程机构信息展示到前台去 organization/views.py from django.views.generic.base import View from organization ...

  3. 如何调用另一个python文件中的代码

    模块的搜索路径 模块的搜索路径都放在了sys.path列表中,如果缺省的sys.path中没有含有自己的模块或包的路径,可以动态的加入(sys.path.apend)即可.下面是sys.path在Wi ...

  4. python 根据路径导入模块

    Import python module NOT on path http://stackoverflow.com/questions/10161568/import-python-module-no ...

  5. 畅通工程&&How Many Tables

    http://acm.hdu.edu.cn/showproblem.php?pid=1232 #include <iostream> #include <stdio.h> #i ...

  6. FDR错误发现率-P值校正学习[转载]

    转自:https://baike.baidu.com/item/FDR/16312044?fr=aladdin  https://blog.csdn.net/taojiea1014/article/d ...

  7. [LeetCode] 697. Degree of an Array_Easy tag: Hash Table

    Given a non-empty array of non-negative integers nums, the degree of this array is defined as the ma ...

  8. VS中代码对齐等快捷键

    在VS2008中,选定代码后,按Ctrl+K+F组合键,可以自动进行代码对齐. 注意:要先按下Ctrl和K,再按下F,因为Ctrl+F是查找的快捷键. 也可以先按下Ctrl+K,再按下Ctrl+F. ...

  9. lnmp1.4 安装php fileinfo扩展 方法

    第一步:在lnmp1.4找到php安装的版本 使用命令 tar   -jxvf   php-7.1.7.tar.bz2 解压 第二步: 在解压的php-7.1.7文件夹里找到fileinfo文件夹,然 ...

  10. zw版【转发·台湾nvp系列Delphi例程】HALCON ConvolImage

    zw版[转发·台湾nvp系列Delphi例程]HALCON ConvolImage procedure TForm1.Button1Click(Sender: TObject);begin img.D ...