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 ...
随机推荐
- File Transfer(并查集)
题目大意:将多个电脑通过网线连接起来,不断查询2台电脑之间是否连通. 问题来源:中国大学mooc 05-树8 File Transfer (25 分) We have a network of com ...
- HDU 6438
Problem Description The Power Cube is used as a stash of Exotic Power. There are n cities numbered 1 ...
- v-on 事件修饰符
事件修饰符: .stop 阻止冒泡 .prevent 阻止默认事件 .capture 添加事件侦听器时使用事件捕获模式 .self 只当该事件在该元素本身时(不是子元素)触发时才回调 .once ...
- Kubernetes-----Endpoints
Endpoints是实现实际服务的端点集合. Kubernetes在创建Service时,根据Service的标签选择器(Label Selector)来查找Pod,据此创建与Service同名的En ...
- 【第八章】MySQL数据库备份—逻辑备份
一.数据库备份 1.命令简介: # mysqldump -h 服务器 -u用户名 -p密码 数据库名 > 备份文件.sql1)关于数据库名: -A, --all-databases ...
- asp之GetArray提取链接地址,以$Array$分隔的代码
'================================================== '函数名:GetArray '作 用:提取链接地址,以$Array$分隔 '参 数:ConStr ...
- Alpha阶段事后诸葛亮会议记录
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2324 组名:可以低头,但没必要 组长:付佳 组员:张俊余 李文涛 孙 ...
- Java 学习笔记 ------第四章 认识对象
本章学习目标: 区分基本类型与类类型 了解对象与参考的关系 从打包器认识对象 以对象观点看待数组 认识字符串的特性 一."=" 和 "==" 当=用于基本类型时 ...
- 第四周 实验一 Java开发环境的熟悉 报告
Java开发环境的熟悉 实验内容 1.IDEA的安装过程 2.使用IDEA代替虚拟机运行.编译.调试Java程序 实验要求 1.没有Linux基础的同学建议先学习<Linux基础入门(新版)&g ...
- 《C》变量
变量的存储方式和生存周期