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. keepalived的log

    vrrp_script chk_http_port { script "</dev/tcp/127.0.0.1/8088" interval 1 weight -2 } ke ...

  2. js-jquery-SweetAlert【一】使用

    一.下载安装 地址:http://t4t5.github.io/sweetalert/ 二.页面引用 <script src="dist/sweetalert.min.js" ...

  3. session超时时间设置

    在Tomcat的web.xml文件中修改如下标签 <session-config> <session-timeout>10</session-timeout> &l ...

  4. [LeetCode] 152. Maximum Product Subarray_Medium tag: Dynamic Programming

    Given an integer array nums, find the contiguous subarray within an array (containing at least one n ...

  5. Locust性能测试1-环境准备与基本使用

    前言 提到性能测试,大部分小伙伴想到的就是LR和jmeter这种工具,小编一直不太喜欢写这种工具类的东西,我的原则是能用代码解决的问题,尽量不去用工具. python里面也有一个性能测试框架Locus ...

  6. Leetcode: Binary Tree Level Order Transversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...

  7. windows下docker的安装并使用

    硬件虚拟化:硬件虚拟化是一种对计算机或操作系统的虚拟.虚拟化对用户隐藏了真实的计算机硬件,表现出另一个抽象计算平台. 打开任务管理器的性能查看是否支持虚拟化技术 下载windows docker ht ...

  8. CAS机制

    ##################################################################### 我们知道多线程操作共享资源时,会出现三个问题:可见性.有序性 ...

  9. 翻译[RFC6238] TOTP: Time-Based One-Time Password Algorithm

    在闲暇时间做了一个TOTP相关的开源项目,在项目初步完成之余,我尝试对[RFC6238]文档进行了翻译,供大家参考与查阅,若有不妥之处,还望各位前辈海涵斧正. [RFC6238] : Time-Bas ...

  10. [转]使用C#开发ActiveX控件全攻略

    前言: 这段时间因为工作的需要,研究了一下ActiveX控件.总结如下: 先说说ActiveX的基本概念. 根据微软权威的软件开发指南MSDN(Microsoft Developer Network) ...