LIGHTOJ 1255-SUBSTRING FREQUENCY 【KMP】
来源:互联网 发布:lcd字库生成软件 编辑:程序博客网 时间:2024/05/21 17:21
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1255
题意:求母串中包含子串的个数,可重叠。
代码:
#include <stdio.h> #include <iostream> #include <math.h> #include <stdlib.h> #include <ctype.h> #include <algorithm> #include <vector> #include <string.h> #include <queue> #include <stack> #include <set> #include <map> #include <sstream> #include <time.h> #include <malloc.h> using namespace std;void get_next(char x[], int m, int Next[]){ int i, j; j = Next[0] = -1; i = 0; while (i < m) { while (-1 != j && x[i] != x[j]) j = Next[j]; Next[++i] = ++j; }}int Next[1001000];long long KMP(char x[], int m, char y[], int n)//x模式串 y主串{ int i, j; long long ans = 0; i = j = 0; get_next(x, m, Next); while (i < n) { while (-1 != j && y[i] != x[j]) j = Next[j]; i++; j++; if (j >= m) { ans++; j = Next[j]; } } return ans;}char a[1000100], b[1000100];int main(){ int t, num; scanf("%d", &t); for (int i = 1; i <= t; i++) { printf("Case %d: ", i); scanf("%s", a); int n = strlen(a); scanf("%s", b); int m = strlen(b); printf("%lld\n", KMP(b, m, a, n)); }}
0 0
- LIGHTOJ 1255-SUBSTRING FREQUENCY 【KMP】
- LightOJ 1255 Substring Frequency (KMP模板)
- LightOJ 1255 - Substring Frequency
- lightoj-1427:Substring Frequency
- light oj 1255 - Substring Frequency (KMP)
- lightoj 1427 Substring Frequency (II) (ac自动机)
- lightoj 1427 Substring Frequency (||) (AC自动机)
- LightOJ 题目1427 - Substring Frequency (II)(AC自动机)
- LightOJ 1427 Substring Frequency (II)(AC自动机裸)
- LightOJ 1427 Substring Frequency (II)(ac自动机水题)
- LightOJ - 1427 - Substring Frequency (II)(AC自动机)
- Light OJ Substring Frequency (II)
- lightOJ 1258 【KMP变形题】
- LightOJ 1268 Unlucky Strings 【KMP+矩阵】
- LightOJ 1258 Making Huge Palindromes (回文&KMP)
- LIGHTOJ 1258 – MAKING HUGE PALINDROMES 【KMP】
- LightOJ 1258 Making Huge Palindromes (回文&KMP)
- LightOJ 1258 - Making Huge Palindromes【kmp】
- 【十九】树以及树的存储结构
- LIGHTOJ 1174 – COMMANDOS 【FLOYD】
- LIGHTOJ 1258 – MAKING HUGE PALINDROMES 【KMP】
- HTML5另类塔防游戏 -『三国战线』发布
- OpenCSP开源程序解析之OPENCSP_Main.cpp
- LIGHTOJ 1255-SUBSTRING FREQUENCY 【KMP】
- 杭电 2200
- 编程流程
- INT ,LONG , LONG LONG类型的范围
- 调试jz2440生成特定后缀的命令
- OpenCSP开源程序解析之OPENCSP_Mutex.cpp
- LIGHTOJ 1007 – MATHEMATICALLY HARD【欧拉函数】
- 文章标题
- PowerPC DevTree