题目大意:题目叙述很多,其实只看输入输出也能明白什么意思,给两个串W,T, 判断T串中包含几个串W。
 
分析:还是基础的KMP应用.......................
直接上代码。
==================================================================================================================
#include<stdio.h>
#include<string.h> const int MAXM = 1e4+;
const int MAXN = 1e6+; void GetNext(char s[], int next[], int N)
{
int i=, j=-;
next[] = -; while(i < N)
{
if(j==- || s[i]==s[j])
next[++i] = ++j;
else
j = next[j];
}
}
int KMP(char W[], char T[], int Nw, int Nt)
{
static int next_w[MAXM];
int i=, j=, ans=; GetNext(W, next_w, Nw); while(i < Nt)
{
while(j==- || (T[i] == W[j] && i<Nt) )
i++, j++; if(j == Nw)
ans++;
j = next_w[j];
} return ans;
} int main()
{
int ncase; scanf("%d", &ncase); while(ncase--)
{
static char W[MAXM], T[MAXN];
int Nw, Nt; scanf("%s%s", W, T); Nw = strlen(W);
Nt = strlen(T); int ans = KMP(W, T, Nw, Nt); printf("%d\n", ans);
} return ;
}

Oulipo - HDU 1686 (KMP模板题)的更多相关文章

  1. Oulipo HDU 1686 KMP模板

    题目大意:求模式串在主串中的出现次数. 题目思路:KMP模板题 #include<iostream> #include<algorithm> #include<cstri ...

  2. hdu 1686 KMP模板

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

  3. HDU 2087 kmp模板题

    s为主串 t为模板串 求t的nextt 加const #include<stdio.h> #include<string.h> #include<algorithm> ...

  4. HDU 1711 - Number Sequence - [KMP模板题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  5. POJ Oulipo KMP 模板题

    http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4 ...

  6. POJ Oulipo(KMP模板题)

    题意:找出模板在文本串中出现的次数 思路:KMP模板题 #include<cstdio> #include<cstring> #include<cmath> #in ...

  7. Number Sequence - HDU 1711(KMP模板题)

    题意:给你一个a串和一个b串,问b串是否是a串的子串,如果是返回b在a中最早出现的位置,否则输出-1   分析:应该是最简单的模板题了吧..... 代码如下: ==================== ...

  8. hdu 1711 Number Sequence(KMP模板题)

    我的第一道KMP. 把两个数列分别当成KMP算法中的模式串和目标串,这道题就变成了一个KMP算法模板题. #include<stdio.h> #include<string.h> ...

  9. HDU 1711Number Sequence【KMP模板题】

    <题目链接> 题目大意: 意思是给出两个串,找出匹配串在模式串中的位置. 解题分析: KMP算法模板题. #include <cstdio> #include <cstr ...

  10. POJ:3461-Oulipo(KMP模板题)

    原题传送:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Description The F ...

随机推荐

  1. maven发布的资源文件到tomcat项目下

    问题:项目中有hibernate的资源文件,src/main/java和src/main/resources都有这些文件,当启动项目时发现出错.但是src/main/java已经修改好了, 经查tom ...

  2. INSERT INTO SELECT FROM 这语句怎么用

    如果两表字段相同,则可以直接这样用. insert into table_a select * from table_b 如果两表字段不同,a表需要b中的某几个字段即可,则可以如下使用: insert ...

  3. angular调用WCF服务,读取文件夹下图片显示列表,下载另存为图片

    读取文件夹下的文件 public string ReadImagesPaths() { string result = string.Empty; try { string path = System ...

  4. 342. Power of Four

    题目: Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example ...

  5. javascript——基本包装类型

    <script type="text/javascript"> //1.Boolean 类型 //2.Number 类型 //3.String 类型 //Boolean ...

  6. 在静态页面html中跳转传值

    在html中通过"?"传值--------<a href="index2.html?name=caoy">静态传值</a> 在跳转到的页 ...

  7. Android ListView+image的使用

    首先创建layout部局文件xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayo ...

  8. MySQL中删除重复数据只保留一条

    用SQL语句,删除掉重复项只保留一条 在几千条记录里,存在着些相同的记录,如何能用SQL语句,删除掉重复的呢 1.查找表中多余的重复记录,重复记录是根据单个字段(peopleId)来判断 SELECT ...

  9. YII 验证邮箱和QQ号码

    //验证邮箱非空,和邮箱格式                    //验证邮箱非空,和邮箱格式                     array("email","e ...

  10. Python学习 - 使用BeautifulSoup来解析网页一:基础入门

    写技术博客主要就是总结和交流的,如果文章用错,请指正啊! 以前一直在使用SGMLParser,这个太费时间和精力了,现在为了毕业设计,改用BeautifulSoup来实现HTML页面的解析工作的. 一 ...