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. (c++) int 转 string,char*,const char*和string的相互转换

    一.int 和string的相互转换 1 int 转化为 string c++ //char *itoa( int value, char *string,int radix); // 原型说明: / ...

  2. [py][mx]django get方法返回login页面

    get方法返回login.html users/views.py def login(request): if request.method == "POST": pass eli ...

  3. JSP表单提交与接收

    JSP表单提交与接收 在Myeclipse中新建web project,在webroot中新建userRegist1.jsp,代码如下 <%@ page contentType="te ...

  4. 深入理解python之一——python3对象的一些特性

    文章使用markdown写的,编辑的时候行间距还可以,显示的时候行间距好小,我也没办法. 首先,需要明白的是python是一种解释性语言标准,他可以由c.java或者其他语言来实现.在python的标 ...

  5. C:\WINDOWS\system32\drivers\etc\hosts 文件的作用

    先来看一看C:\WINDOWS\system32\drivers\etc\hosts 系统原来的hosts文件(未经过改动) 打开原来的hosts文件,查看原来的内容 host是一个没有扩展名的系统文 ...

  6. Django的基本开发环境配置和MTV模型

    一.MTV模型 Django的MTV分别代表: Model(模型):负责业务对象与数据库的对象(ORM) Template(模版):负责如何把页面展示给用户 View(视图):负责业务逻辑,并在适当的 ...

  7. Django-made基础

    知识预览 ORM 创建表(建立模型) 添加表记录 查询表记录 修改表记录 删除表记录 回到顶部 ORM 映射关系: 表名 <-------> 类名 字段 <-------> 属 ...

  8. http协议基础(八)请求首部字段

    请求首部字段 定义:请求首部字段是从客户端到服务器发送请求报文中所使用的字段,里面包含了附加信息.客户端信息以及对响应内容相关的优先级等内容 1.Accept 通知服务器用户代理可处理的媒体类型及媒体 ...

  9. 2016-2017-2 20155309南皓芯java第五周学习总结

    教材内容总结 这一周学习的进度和前几周比较的话是差不多的,都是学习两章. 异常处理 1.理解异常架构 2.牚握try...catch...finally处理异常的方法 3.会用throw,throws ...

  10. Impala shell详解

    不多说,直接上干货! 查看帮助文档 impala-shell -h 刷新整个云数据 impala-shell -ruse impala;show tables; 去格式化,查询大数据量时可以提高性能 ...