poj 3461
来源:互联网 发布:大数据平台开发面试 编辑:程序博客网 时间:2024/05/16 03:11
链接:http://poj.org/problem?id=3461
KMP:
AC code:
#include<iostream>#include<cstring>#include<stdio.h>using namespace std;char p[10005],q[1000005];int nextval[10005];void getnextval(char p[],int m){ int i,j=-1; nextval[0]=-1; for(i=1;i<m;++i) { while(j!=-1&&p[j+1]!=p[i]) j=nextval[j]; if(p[j+1]==p[i]) j++; nextval[i]=j; }}int KMP(char p[],char q[],int m,int n){ int i=0,j=-1,cnt=0; for(i=0;i<n;++i) { while(j!=-1&&p[j+1]!=q[i]) j=nextval[j]; if(p[j+1]==q[i]) j++; if(j==m-1) { cnt++; } } return cnt;}int main(){ int test; scanf("%d",&test); while(test--) { scanf("%s%s",p,q); int m=strlen(p),n=strlen(q); getnextval(p,m); printf("%d\n",KMP(p,q,m,n)); } return 0;}
- poj 3461
- POJ 3461
- poj 3461
- poj 3461
- POJ 3461
- poj 3461
- poj 3461
- POJ 3461
- poj 3461
- poj 3461
- POJ 3461
- POJ 3461
- POJ 3461
- POJ 3461
- poj 3461
- POJ 3461
- POJ 3461
- poj 3461
- win7下打开CHM,索引选项出错
- 清除文件夹下SVN信息
- 编译DataNucleus Tutorial for JDO using Ant成功
- 分治、时间空间的权衡:最大合的连续字串问题 (PAT 1007)
- poj 1276 背包啊
- poj 3461
- 解决 “无法安装 Visual Studio 2010 Service Pack 1,因为此计算机的状态不支持”
- 这25条鲜活信息,有助你简单了解当下的中国互联网
- mips 异常处理
- 查询优化管道分析思路
- CSRF | XSRF 跨站请求伪造
- android adb shell 的ls命令出现奇怪的字符
- IOS中运行出现如下错误的解决办法
- vim 配置