hihocoder#1015:(KMP)
来源:互联网 发布:算法还是编码 编辑:程序博客网 时间:2024/06/06 19:55
题目:http://hihocoder.com/problemset/problem/1015
题目分析:KMP裸题,GDKOI前敲敲模板……
CODE:
题目分析:KMP裸题,GDKOI前敲敲模板……
CODE:
#include<iostream>#include<string>#include<cstring>#include<cmath>#include<cstdio>#include<cstdlib>#include<stdio.h>#include<algorithm>using namespace std;const int maxl=10010;int Next[maxl];string s,t;int n;int main(){freopen("c.in","r",stdin);freopen("c.out","w",stdout);scanf("%d",&n);for (int i=1; i<=n; i++){cin>>t;cin>>s;int tlen=t.size();int slen=s.size();Next[0]=Next[1]=0;int k=0;for (int i=2; i<=tlen; i++){while ( k && t[k]!=t[i-1] ) k=Next[k];if ( t[k]==t[i-1] ) k++;Next[i]=k;}k=0;int ans=0;for (int i=1; i<=slen; i++){while ( k && t[k]!=s[i-1] ) k=Next[k];if ( t[k]==s[i-1] ) k++;if ( k==tlen ) ans++;}printf("%d\n",ans);}return 0;}
0 0
- hihocoder#1015:(KMP)
- hihocoder 1015(KMP)
- hihocoder-1015 KMP算法(KMP)
- hihoCoder 1015 KMP算法(kmp)
- hihocoder #1015 : KMP算法 (模板)
- hihoCoder - 1015 - KMP算法
- [HiHoCoder]#1015 : KMP算法
- hihoCoder#1015 KMP算法
- hihocoder#1015 : KMP算法
- hihocoder 1015 KMP
- hihoCoder 1015 : KMP算法
- hihoCoder #1015 : KMP算法
- kmp 学习 hihocoder #1015
- hihoCoder#1015 KMP算法
- hihocoder 1015 KMP
- hihocoder #1015 KMP算法
- hihoCoder 1015 KMP算法
- hihoCoder 1015 KMP算法
- bzr 工具的介绍与使用
- Netty自定义协议的粘包和拆包处理
- POJ 3518 Prime Gap 可能会
- C++深拷贝浅拷贝
- 剖析Asp.Net路由系统
- hihocoder#1015:(KMP)
- 自己写控制浮点数显示位数
- Mysql注入之一 联合注入
- Linux service network restart重启网络失败
- c++中的vector
- 完美处理SpringMVC文件上传的一系列问题(无法获取参数、断点、分片等)
- c语言指针链表
- POJ 3517 And Then There Was One 可能会
- VS2010鼠标变为灰色块的解决方案