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 ...
随机推荐
- golang笔记——命令
1.GO命令一览 GO提供了很多命令,包括打包.格式化代码.文档生成.下载第三方包等等诸多功能,我们可以通过在控制台下执行 go 来查看内置的所有命令 下面来逐个介绍,也可以详细参考 https:// ...
- Supervisor 安装与配置
Supervisor是一个进程监控程序. 满足的需求是:我现在有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了 ...
- JS keycode 事件响应
<script language="javascript"> function keyevent(){ if(event.keyCode==13) alert(&quo ...
- XMAL语法系列之-(2)---WPF控件继承图
WPF控件继承图 1 FrameworkElement 1.1 Panel(面板类元素) 1.1.1 Canvas 1.1.2 DockPanel 1.1.3 Grid 1.1.4 TabPanel ...
- html 补充
替换文本属性(Alt)alt 属性用来为图像定义一串预备的可替换的文本.替换文本属性的值是用户定义的.<img src="boat.gif" alt="Big Bo ...
- Thank you for your resubmission. Performance - 2.3.10 We noticed that your app or its metadata includes irrelevant third-party platform information. Specifically, Android logo is mentioned in the
被拒很多次,各种修改,最后发现是提交的时候,含有安卓的图标!欲哭无泪呀! Thank you for your resubmission. Performance - 2.3.10 We notice ...
- C#调用java类、jar包方法
一.将已经编译后的java中Class文件进行打包:打包命令JAR 如:将某目录下的所有class文件夹全部进行打包处理: 使用的命令:jar cvf test.jar -C com/ . 其中tes ...
- PHPCMS系统使用的弹出窗口插件artDialog
来源: http://aui.github.io/artDialog/doc/index.html (官方) http://lab.seaning.com/ http://www.mb5u.com/ ...
- Android_bug之Default Activity not found
在运行自己修改默认的MainActivety,运行自己的Mainactivety时,碰到这个问题Could not identify launch activity: Default Activity ...
- Hello 2016
Hello 2016 I am really happy to work and study here. Nothing is better than be oneself ! It's import ...