poj 3461 Oulipo
2016-04-29 19:34
337 查看
和hihocoder一样的一道题。。
不过G++超时,也不是很懂。。
不过G++超时,也不是很懂。。
#include<cstdio> #include<iostream> #include<cstring> #include<vector> #include<string> using namespace std; string a,b; vector<int>next; int main() { int n; cin>>n; while(n--) { a.clear(); b.clear(); next.clear(); cin>>a>>b; int lena=a.size(); int lenb=b.size(); next.push_back(-1); int i=0; int j=next[0]; while(i<lena) { if(j==-1||a[i]==a[j]) { i++; j++; next.push_back(j); } else { j=next[j]; } } i=0; j=0; int ans=0; while(i<lenb) { if(j==-1||b[i]==a[j]) { i++; j++; } else { j=next[j]; } if(j==lena) { ans++; } } cout<<ans<<endl; } return 0; }
相关文章推荐
- KMP算法的C#实现方法
- JavaScript中数据结构与算法(五):经典KMP算法
- 字符串算法--KMP--Java实现
- 初学ACM - 组合数学基础题目PKU 1833
- KMP算法(转载)
- kmp算法实现
- POJ ACM 1001
- POJ ACM 1002
- 1611:The Suspects
- POJ1089 区间合并
- KMP算法详解
- linux kernel data struct: KMP算法实现
- POJ 2635 The Embarrassed Cryptographe
- POJ 3292 Semi-prime H-numbers
- POJ 2773 HAPPY 2006
- POJ 3090 Visible Lattice Points
- POJ-2409-Let it Bead&&NYOJ-280-LK的项链
- POJ-1695-Magazine Delivery-dp
- POJ1523 SPF dfs
- POJ-1001 求高精度幂-大数乘法系列