hdu 1711 Number Sequence
2015-11-03 16:05
393 查看
题目链接:hdu 1711 Number Sequence
kmp模板题
kmp模板题
#include<iostream> #include<cstring> #include<cstdio> #define maxn 11111 using namespace std; void get_next(char d[],int Next[]) { int i=0,k=-1; int len=strlen(d); Next[0]=-1; while(i<len) { if(k==-1||d[i]==d[k]) { i++; k++; Next[i]=k; } else k=Next[k]; } //for(int i=0;i<len;i++) cout<<Next[i]<<' '; //cout<<endl; } int kmp(char s[],char d[],int Next[]) { int i=0,j=0; int slen=strlen(s); int dlen=strlen(d); while(i<slen) { if(s[i]==d[j]||j==-1) i++,j++; else j=Next[j]; if(j==dlen) return i-dlen; } return -1; } int main() { char s[maxn],d[maxn]; int Next[maxn]; while(gets(s),gets(d)) { get_next(d,Next); cout<<kmp(s,d,Next)<<endl; } return 0; }
相关文章推荐
- UICollectionView(二)自定义布局UICollectionViewLayout
- 设置segue跳转页面
- UICollectionView(一)基本概念
- UIStackView使用
- iOS9 之后的UIAlertView 的写法
- UIActivityIndicatorView的使用说明
- Ant-------默认是build.xml 改为其他的名字
- 基于MVC4+EasyUI的Web开发框架经验总结(8)--实现Office文档的预览
- UITableView常用操作
- NSOperationQueue
- 锁表参数 enque/table_size via ECC6 EHP7
- 【UER #5】万圣节的南瓜灯
- UINavigationController层次关系
- Web Service单元测试工具实例介绍之SoapUI
- The project cannot be built until build path errors are resolved解决方案
- Longest Increasing Subsequence
- hdoj 3450 Counting Sequences 【离散化 + 树状数组优化dp】
- UISwipeGestureRecognizer手势识别
- UINavigationItem UINavigationBar 关系分析
- Ligerui表格基本操作(二)