Match:Oulipo(POJ 3461)

题目大意:给你一个字符串,要你找到字符串包含指定子串的个数
只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧
#include <iostream>
#include <algorithm>
#include <functional>
#include <string.h> using namespace std; typedef int Position;
static char Text[], Word[];
static int Next[]; void KmpSearch(const int, const int);
void GetNext(const int); int main(void)
{
int case_sum;
scanf("%d", &case_sum);
getchar(); while (case_sum--)
{
scanf("%s", Word);
scanf("%s", Text);
KmpSearch(strlen(Word), strlen(Text));
}
return EXIT_SUCCESS;
} void KmpSearch(const int w_len, const int t_len)
{
Position i = , j = ;
int k_count = ;
GetNext(w_len); while (i < t_len)
{
if (j == - || Text[i] == Word[j])
{
i++;
j++;
if (j == w_len)
{
k_count++;
j = Next[j];
}
}
else j = Next[j];
}
printf("%d\n", k_count);
} void GetNext(const int w_len)
{
Position i = , k = -;
Next[] = -; while (i < w_len)
{
if (k == - || Word[i] == Word[k])
{
i++;
k++;
Next[i] = Word[i] != Word[k] ? k : Next[k];
}
else k = Next[k];
}
}

Match:Oulipo(POJ 3461)的更多相关文章
- 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 ...
- (KMP)Oulipo -- poj --3461
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 ...
- AC日记——Oulipo poj 3461
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37958 Accepted: 15282 Description The ...
- Oulipo POJ - 3461(kmp,求重叠匹配个数)
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- 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 ...
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- POJ 3461 Oulipo 【KMP统计子串数】
传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submission ...
- poj 3461 Oulipo,裸kmp
传送门 Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32373 Accepted: 13093 Desc ...
随机推荐
- php 冒泡排序
public function demo($arr){ $len = count($arr); if ($len == 1) { return $arr; } else { for ($i = 1; ...
- 免费的ER 设计软件调研
目标: 找到一个免费的ER 设计软件, 适合数据仓库项目开发. 结果: 经初步调研, Oracle的 SQL Developer Data Modeler基本满足需求. 但在功能和操作性等方面, 较P ...
- ML_R Kmeans
Kmeans作为机器学习中入门级算法,涉及到计算距离算法的选择,聚类中心个数的选择.下面就简单介绍一下在R语言中是怎么解决这两个问题的. 参考Unsupervised Learning with R ...
- 关于外部引用JS,中文乱码的问题
asp.net 页面默认编码为UTF-8, 如果js嵌套写在asp.net中,不会导致中文乱码,因为他们具有相同的编码 外部引用js由于编码格式与asp.net的编码不同,javascript编码默认 ...
- 论在Windows下远程连接Ubuntu
Ubuntu下1:下载xrdp sudo apt-get install xrdp 2: urs/share/applications 下找到 远程桌面 设置成这样 Windows下 1; ...
- Python 集合set添加删除、交集、并集、集合操作符号
在Python中集合set是基本数据类型的一种,它有可变集合(set)和不可变集合(frozenset)两种.创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方法. 1. ...
- php正则预查
php正则预查 // 把ing结尾的单词词根部分(即不含ing部分)找出来$str = 'hello ,when i am working , don not coming';零宽度:站在原地往前看, ...
- FineUI第十四天---布局之垂直布局和水平布局
布局值水平布局和垂直布局 垂直盒子布局和水平盒子布局非常灵活易用,在很大程度上能够取代锚点布局,行布局和列布局. 1.垂直盒子布局: BoxConfigAlign:控制子容器的的尺寸 Start:位于 ...
- Java设计模式 之 工厂方法模式
1. 使用设计模式的好处:可提高代码的重复性,让代码更容易被他人理解,保证代码的可靠性. 2. 工厂模式定义:就是创建一个工厂类来创建你需要的类,工厂模式包括工厂模式和抽象工厂模式,抽象工厂模式是工厂 ...
- 为在韶大痛苦而不能用手机、Pad等上网的同志造福!
目标:共享咱们校园网,让更多的人或更多的设备冲浪去! 基本条件:一台带无线功能的笔记本,一个可以上网的账号与pwd,最好为Windows7以上的操作系统,如果是XP,则需要打个.net framewo ...