HDU 1686 Oulippo
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的更多相关文章
- hdu 1686 KMP模板
// hdu 1686 KMP模板 // 没啥好说的,KMP裸题,这里是MP模板 #include <cstdio> #include <iostream> #include ...
- 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 ...
- HDU - 1686 Oulipo KMP匹配运用
id=25191" target="_blank" style="color:blue; text-decoration:none">HDU - ...
- hdu 1686 Oulipo KMP匹配次数统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 分析:典型的KMP算法,统计字符串匹配的次数. 用Next数组压缩时间复杂度,要做一些修改. / ...
- hdu 1686 & poj 2406 & poj 2752 (KMP入门三弹连发)
首先第一题 戳我穿越;http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意好理解,每组输入一个子串和一个母串,问在母串中有多少个子串? 文明人不要暴力 ...
- HDU 1686 - Oulipo - [KMP模板题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 Time Limit: 3000/1000 MS (Java/Others) Memory Li ...
- HDU 1686 Oulipo(KMP变形求子串出现数目(可重))
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:给两个字符串A,B求出A中出现了几次B(计算重复部分). 解题思路:稍微对kmp()函 ...
- hdu 1686 Oulipo kmp算法
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目: Problem Description The French author George ...
- hdu 1686 Oulipo (kmp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1686 题目大意:寻找子链在母链中出现的次数. #include <iostream> #i ...
随机推荐
- Linux 线程实现机制分析 Linux 线程模型的比较:LinuxThreads 和 NPTL
Linux 线程实现机制分析 Linux 线程实现机制分析 Linux 线程模型的比较:LinuxThreads 和 NPTL http://www.ibm.com/developerworks/c ...
- 13 jmeter性能测试实战--FTP程序
需求 上传一个文件到服务器(put),下载一个文件到本地(get). 测试步骤 1.创建一个线程组. 2.线程组-->添加-->配置元件-->FTP请求缺省值(可有可无,相当于给“服 ...
- DOM对象与Jquery对象转换
dom对象的样式是这么加的(js) .style.background = “red”; jquery对象样式是这么加的(jq) .css(“background”,”red”); <div i ...
- 完成向后台添加用户的ssm项目,完整版
1:ssm框架整合 1.1添加maven依赖pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns: ...
- 关hashMap跟hashTable的区别
1.HashMap和Hashtable都实现了Map接口 2.HashMap是非synchronized,而Hashtable是synchronized 3.HashTable使用Enumeratio ...
- R中apply等函数用法[转载]
转自:https://www.cnblogs.com/nanhao/p/6674063.html 1.apply函数——对矩阵 功能是:Retruns a vector or array or lis ...
- jquery 实现iframe 自适应高度
转自: http://www.cnblogs.com/luluping/archive/2009/04/17/1437843.html 超级简单的方法,也不用写什么判断浏览器高度.宽度啥的.下面的两种 ...
- set的一些数学运算
python的set和其他语言类似, 是一个无序不重复元素集, 基本功能包括关系测试和消除重复元素. 集合对象还支持union(联合), intersection(交), difference(差)和 ...
- FRM-92095: Oracle Jnitiator version too low – please install version 1.1.8.2 or higher
打开EBS,系统报:FRM-92095: Oracle JInitiator 版本太旧. 请安装版本1.1.8.2或更高版本 (英文的错误信息是:FRM-92095: Oracle JInitiato ...
- JSON自动生成相关类
开源项目地址:https://jsonclassgenerator.codeplex.com/SourceControl/latest 太好用了,这个