ZOJ 3957 Knuth-Morris-Pratt Algorithm
来源:互联网 发布:跟淘宝合作的购物软件 编辑:程序博客网 时间:2024/06/12 21:27
In computer science, the Knuth-Morris-Pratt string searching algorithm (or KMP algorithm) searches for occurrences of a “word” W within a main “text string” S by employing the observation that when a mismatch occurs, the word itself embodies sufficient information to determine where the next match could begin, thus bypassing re-examination of previously matched characters.
Edward is a fan of mathematics. He just learnt the Knuth-Morris-Pratt algorithm and decides to give the following problem a try:
Find the total number of occurrence of the strings “cat” and “dog” in a given string s.
As Edward is not familiar with the KMP algorithm, he turns to you for help. Can you help Edward to solve this problem?
问串 S 中有多少子串为 cat
或 dog
?
解题思路
使用 STL 直接判断即可。
代码
#include<bits/stdc++.h>using namespace std;string s, t;int main(){ int T; scanf("%d",&T); while(T--) { int cnt =0 ; cin>>s; for(int i=0;i<s.size() - 2;i++) { t = s.substr(i, 3); if(t == "dog" || t== "cat") cnt++; } printf("%d\n", cnt); }}
- ZOJ 3957 Knuth-Morris-Pratt Algorithm
- zoj 3957 Knuth-Morris-Pratt Algorithm
- Knuth-Morris-Pratt algorithm
- Knuth-Morris-Pratt Algorithm
- The Knuth-Morris-Pratt Algorithm
- ACM刷题之ZOJ————Knuth-Morris-Pratt Algorithm
- The Knuth-Morris-Pratt
- The Knuth-Morris-Pratt Algorithm in my own words
- The Knuth-Morris-Pratt Algorithm in my own words
- The Knuth-Morris-Pratt Algorithm in my own words
- KMP算法(The Knuth-Morris-Pratt Algorithm)
- KMP算法——Knuth–Morris–Pratt algorithm
- The Knuth-Morris-Pratt Algorithm KMP模式匹配算法
- zoj3957——Knuth-Morris-Pratt Algorithm(KMP)
- The Knuth-Morris-Pratt Algorithm in my own words
- KMP 算法(Knuth–Morris–Pratt algorithm)
- Knuth-Morris-Pratt string matching
- KMP(Knuth-Morris-Pratt)算法
- Convert QWERTY to Dvorak
- echarts入门
- 1060. 爱丁顿数(25)
- Animation之闪烁的星星
- 归并排序
- ZOJ 3957 Knuth-Morris-Pratt Algorithm
- 链表列表
- opencv Canny边缘检测
- python 数组和json字符串 互相转换
- vmmap内存检查工具
- leetcode题
- 深入浅出LSTM神经网络
- 精品:Spline导数及曲率计算(判断曲线的弯曲程度)
- iOS源码解析—SDWebImage(SDImageCache)