POJ--3461
原题链接:http://poj.org/problem?id=3461
分析:求一个串在另一个串中出现的次数,显然用KMP可以解决。
#include<cstdio>
#include<cstring>
#include<algorithm>
#define maxn1 10005
#define maxn2 1000005
using namespace std;
char s[maxn1],t[maxn2];
int next[maxn1],sum,len1,len2;
void get_next()
{
int i,j;len1=strlen(s);
next[]=-;
i=;j=-;
while(i<len1){
if(j==-||s[i]==s[j]){
i++;j++;
next[i]=j;
}
else j=next[j];
}
}
void kmp()
{
sum=;
get_next();
int i=-,j=-;len2=strlen(t);
while(i<len2){
if(j==-||t[i]==s[j])
{
i++;j++;
}
else j=next[j];
if(j==len1){
sum++;
j=next[j];
}
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s%*c%s",s,t);
kmp();
printf("%d\n",sum);
}
return ;
}
POJ--3461的更多相关文章
- POJ 3461 Oulipo
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- 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 ...
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo(模式串在主串中出现的次数)
题目链接:http://poj.org/problem?id=3461 题意:给你两个字符串word和text,求出word在text中出现的次数 思路:kmp算法的简单应用,遍历一遍text字符串即 ...
- (KMP)Oulipo -- poj --3461
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- POJ - 3461 (kmp)
题目链接:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- POJ 3080 Blue Jeans、POJ 3461 Oulipo——KMP应用
题目:POJ3080 http://poj.org/problem?id=3080 题意:对于输入的文本串,输出最长的公共子串,如果长度相同,输出字典序最小的. 这题数据量很小,用暴力也是16ms,用 ...
- poj 3461 字符串单串匹配--KMP或者字符串HASH
http://poj.org/problem?id=3461 先来一发KMP算法: #include <cstdio> #include <cstring> #include ...
随机推荐
- 母版页 MasterPage
母版页是一个扩展名为.master的ASP.NET文件,主要是为了应用程序创建统一的用户功能界面和样式. ContentPlaceHolder控件只能在母版页中使用,在平常的web页面使用,会发生解析 ...
- openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 二
openstack-r版(rocky)搭建基于centos7.4 的openstack swift对象存储服务 一 openstack-r版(rocky)搭建基于centos7.4 的openstac ...
- hashlib模块使用详情
python常用模块目录 一:hashlib简介 1.什么叫hash:hash是一种算法(不同的hash算法只是复杂度不一样)(3.x里代替了md5模块和sha模块,主要提供 SHA1, SHA224 ...
- Linux 150命令之 文件和目录操作命令 chattr lsattr find
chattr添加隐藏权限 lsattr查看隐藏权限 参数 a文件内容不能删除,只能追加 >> [root@mysql tmp]# chattr +a 1.txt [root@mysql t ...
- Java:重写equals()和hashCode()
Java:重写equals()和hashCode() 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用instan ...
- java不用任何已有方法完全自写的去重法
package aa; class InsertSort{ private long[] a; private int nElems; //构造方法 public InsertSort(int max ...
- High School: Become Human(数学思维)
Year 2118. Androids are in mass production for decades now, and they do all the work for humans. But ...
- bash编程2
bash基础编程 前言:条件测试语法有两种书写模式,一种时[expression] ,另外一种是[[exprssion]] ,为了在书写条件测试的过程中,不让大家将两种格式互相混淆,那么在这里只讲一种 ...
- Beta阶段冲刺第一天
提供当天站立式会议照片一张 讨论项目每个成员的昨天进展 昨天开始了Beta阶段的冲刺,总体讨论了一下这个阶段的任务,然后明确了个人分工. 讨论项目每个成员的存在问题 第一天暂时还没有什么问题,可能最大 ...
- PAT 甲级 1027 Colors in Mars
https://pintia.cn/problem-sets/994805342720868352/problems/994805470349344768 People in Mars represe ...