字符串 KMP HDU 1686
来源:互联网 发布:石头纸 知乎 编辑:程序博客网 时间:2024/04/30 04:42
#include <stdio.h>#include <string.h>/*3BAPCBAPCAZAAZAZAZAVERDIAVERDXIVYERDIAN水题KMP */const int M = 10005; const int N = 1000005;char a[N],b[M];int next[M];//一个没注意写成char 查了半天 int lena,lenb;void getNext(){int j=-1;next[0]=-1;for(int i=1;i<lenb;i++){while(j>=0 && b[i]!=b[j+1])j=next[j];if(b[i]==b[j+1])j++;next[i]=j;}}int kmp(){int j=next[0];int ans=0;for(int i=0;i<lena;i++){while(j>=0 && a[i]!=b[j+1])j=next[j];if(a[i]== b[j+1])j++;if(j==lenb-1){ans++;j=next[j];//重置回去 }}return ans;}int main(){int T;scanf("%d",&T);while(T--){scanf("%s%s",b,a);lena=strlen(a);lenb=strlen(b);getNext();printf("%d\n",kmp()); }return 0;}
0 0
- 字符串 KMP HDU 1686
- HDU 1686 Kmp(字符串匹配)
- hdu 1686 Oulipo kmp字符串比较
- HDU 1686 Oulipo(KMP算法 字符串匹配)
- 【kmp字符串匹配】hdu 1686 Oulipo
- 【KMP求字符串匹配次数】 hdu 1686
- 字符串 KMP HDU 1711
- 字符串 KMP HDU 4749
- 字符串 KMP HDU 2087
- 字符串 KMP HDU 3746
- 字符串 KMP HDU 2203
- 字符串 KMP HDU 2594
- hdu 1867 链接字符串+kmp
- HDU:1686 Oulipo(KMP包含字符串(不是分割))
- HDU 1686 Oulipo (kmp)
- HDU-1686(KMP)
- hdu 1686 kmp Oulipo
- hdu 1686 KMP
- PHP假期复习(三)---http协议
- 【zzulioj 1893 985的数学难题】
- java和页面中文乱码问题
- IntelliJ IDEA 设置代码提示或自动补全的快捷键
- Find Leaves of Binary Tree
- 字符串 KMP HDU 1686
- 需要认识的c math 函数
- PHP假期复习(四)---web技术
- 运算符重载
- hdu 5818 Joint Stacks 栈
- Error22error C1189: #error : The C++ Standard Library forbids macroizing keywords. Enable warning
- POJ2002Squares(哈希)
- Effective Objective-C 2.0 第15条:用前缀避免命名空间冲突
- 数据结构上机实验之顺序查找