-->
当前位置:首页 > 题库

PROGRAMMING:String pattern matching (KMP)

Luz5年前 (2021-05-10)题库448
Given a string text and a pattern string pattern, find the number of times pattern appears in text. The characters in text and pattern are English uppercase or lowercase letters. Patterns appearing in different positions in text can overlap.
###Input format:
The input consists of two lines, the string text and the pattern string pattern.
###Output format:
Output an integer indicating the number of times the pattern appears in text.
###Input sample 1:
```in
zyzyzyz
zyz
```
###Output sample 1:
```out
three
```
###Input sample 2:
```in
AABAACAADAABAABA
AABA
```
###Output sample 2:
```out
three
```
###Data range and tips:
1 ≤ text, the length of pattern ≤$$10 ^ {6} $$, text and pattern only contain upper and lower case letters.







answer:If there is no answer, please comment