POJ 3461 Oulipo KMP算法
2012-07-20 12:32
399 查看
http://poj.org/problem?id=3461
纯KMP不多说上代码= =。。
View Code
纯KMP不多说上代码= =。。
View Code
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int pre[10005]; void predeal(char s[]) { int len,i,j; len = strlen(s); pre[0] = -1; j = -1; for(i = 1;i < len;i++) { while(j > -1 && s[j+1] != s[i]) j = pre[j]; if(s[j+1] == s[i]) j++; pre[i] = j; } } int kmp(char s1[],char s2[]) { int len1,len2,i,j,num; len1 = strlen(s1); len2 = strlen(s2); num = 0; for(i = 0,j = -1;i < len2;i++) { while(j > -1 && s1[j+1] != s2[i]) j = pre[j]; if(s1[j+1] == s2[i]) j++; if(j == len1-1) j = pre[j],num++; } return num; } int main() { int n,i,j; char s2[1000005],s1[10005]; scanf("%d",&n); while(n--) { memset(pre,0,sizeof(pre)); scanf("%s",s1); scanf("%s",s2); predeal(s1); int ans; ans = kmp(s1,s2); printf("%d\n",ans); } return 0; }
相关文章推荐
- POJ 3461 Oulipo KMP算法题解
- POJ 3461 Oulipo (KMP算法)
- POJ 3461 Oulipo (KMP算法)
- poj 3461 Oulipo 字符串匹配 KMP算法
- POJ 3461 Oulipo(字符串匹配,KMP算法)
- POJ 3461 Oulipo[附KMP算法详细流程讲解]
- POJ 3461 Oulipo(——KMP算法)
- (串的模式匹配4.6.2)POJ 3461 Oulipo(KMP算法的应用——求一个单词在一行文本中的出现次数)
- 字符串匹配之KMP算法(POJ 3461 Oulipo)
- POJ3461——Oulipo KMP算法的应用
- POJ 3461 Oulipo KMP算法题解
- poj 3461 Oulipo KMP算法
- Poj 3461 Oulipo(KMP算法)
- kmp算法(POJ 3461 Oulipo)
- POJ-3461 Oulipo-匹配的字符有几个(KMP算法)
- [POJ] 3461 Oulipo [KMP算法]
- poj--3461 Oulipo -------KMP算法
- POJ 3461 Oulipo 深刻理解KMP算法next数组含义
- POJ 3461 Oulipo KMP模板题
- POJ 3461 Oulipo---kmp