poj3461Oulipo
来源:互联网 发布:windows route delete 编辑:程序博客网 时间:2024/06/04 23:21
</pre><pre name="code" class="cpp">#include <iostream>#include <cstdio>#include <cstring>using namespace std;const int N=10005;const int MAXN=1000005;/*void _next(const char *s,int *next){// 以数组的下标表示已经匹配的字符数 ,以下标对应的数据存储 真后缀(自身最长前缀)的长度 int i,j,n=strlen(s); next[0]=-1;// for(j=-1,i=0;i<n;++i){ while(j!=-1&&s[i]!=s[j]){ j=next[j]; } next[i+1]=++j; }}*/void _next(const char *s,int *next){// 以数组的下标表示已经匹配的字符数 ,以下标对应的数据存储 真后缀(自身最长前缀)的长度 next[0]=-1;// int j=-1; for(int i=1;s[i];++i){ while(j!=-1&&s[i]!=s[j+1]){ j=next[j]; } if(s[i]==s[j+1])j++; next[i]=j; }}int kmp(char *a,char *b,int *next){ int i,j=-1,ret=0; for(i=0;a[i];i++){ while(j!=-1&&a[i]!=b[j+1])j=next[j]; if(a[i]==b[j+1])j++; if(!b[j+1]){ ret++; j=next[j]; } } return ret;}int main(){ char w[N],t[MAXN]; int T,next[N]; bool first=true; cin>>T; while(T--){ memset(next,0,sizeof(next)); if(first){ getchar(); first=false; } gets(w); gets(t); _next(w,next); //for(int i=0;i<strlen(w);i++)cout<<next[i]<<endl; printf("%d\n",kmp(t,w,next)); } return 0;}
0 0
- poj3461Oulipo
- poj3461Oulipo
- POJ3461Oulipo
- poj3461Oulipo
- POJ3461Oulipo[KMP]
- poj3461Oulipo kmp
- 寒假训练--KMP--poj3461Oulipo
- poj3461Oulipo(hash)
- VC++玩转Native Wifi API 3---GOTO在释放资源时的作用
- 不简单的JAVA内部类
- 变量的引用类型和非引用类型的区别
- C++-虚函数,多态性,纯虚函数,抽象类
- hdu 2570 迷瘴
- poj3461Oulipo
- hdu 3038 How Many Answers Are Wrong(并查集)
- 暑期个人赛--第七场--C
- 用树状数组求区间最值
- C++-函数覆盖和隐藏
- 为什么要定义接口?
- C++-类的操作
- 30天自制操作系统之第11天 制作窗口
- 数论之欧几里得算法hdu1019