POJ 3461 && HDU 1686 Oulipo(kmp)
来源:互联网 发布:天猫手续费比淘宝高 编辑:程序博客网 时间:2024/05/20 20:18
Description
求a串在b串中出现的次数
Input
第一行为用例组数t,每组用例占两包括两个字符串b串和a串
Output
对于每组用例,输出a串在b串中出现的次数
Sample Input
3
BAPC
BAPC
AZA
AZAZAZA
VERDI
AVERDXIVYERDIAN
Sample Output
1
3
0
Solution
kmp基础题
Code
#include<cstdio>#include<cstring>#include<iostream>using namespace std;char a[1111111],b[11111];int next[1111111];int main(){ int t; cin>>t; while(t--) { scanf("%s",b); scanf("%s",a); int la=strlen(a); int lb=strlen(b); int sum=0; for(int i=0,j=-1;i<=lb;i++,j++) { next[i]=j; while(~j&&b[i]!=b[j]) j=next[j]; } for(int i=0,j=0;i<=la;i++,j++) { if(j==lb) { sum++; j=next[j]; } while(~j&&a[i]!=b[j]) j=next[j]; } printf("%d\n",sum); } return 0;}
0 0
- POJ 3461 && HDU 1686 Oulipo(kmp)
- Oulipo (poj 3461&&hdu 1686) KMP
- POJ 3461 - Oulipo(KMP)
- POJ-3461 Oulipo(KMP)
- Poj 3461 Oulipo (KMP)
- POJ---3461-Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- POJ 3461 Oulipo(KMP)
- 【POJ 3461】Oulipo(kmp)
- poj 3461 Oulipo(KMP)
- poj 3461 Oulipo(KMP)
- HDU 1686 Oulipo(kmp)
- HDU 1686 Oulipo(KMP)
- hdu 1686 Oulipo (kmp)
- HDU - 1686 Oulipo(KMP)
- HDU 1686 Oulipo (kmp)
- hdu 1686 Oulipo(KMP)
- HDU 1686 Oulipo(kmp)
- [树状数组] poj3468 A Simple Problem with Integers
- 代码流程分析一:Settings中默认值的流程-显示-自动旋转屏幕
- #ifdef DEBUG的理解
- ios的新App加急上线可以选择邮件催办
- 按键事件在activity中的流程
- POJ 3461 && HDU 1686 Oulipo(kmp)
- 创建一个简单的按钮
- app版本更新的四种实现方式
- swift学习03-快速学习常量变量
- Swift之 ? 和 !用法
- EditPlus 在线获取注册码
- ffmeg 反交错
- 股票英语
- iOS多任务开发