6873.String Matching

Time Limit: 1s Memory Limit: 512MB

Given a string and a pattern, your task is to count the number of positions where the pattern occurs in the string.

Input Format(From the terminal/stdin)

The first input line has a string of length $n$ , and the second input line has a pattern of length $m$ . Both of them consist of characters a–z.

  • $1 \le n,m \le 10^6$

Output Format(To the terminal/stdout)

Print one integer: the number of occurrences.

Sample Input

Copy
saippuakauppias
pp
               \n
  \n

Sample Output

Copy
2
 \n
Source: CSES, String Algorithms, 1753

Submit

请先 登录

© 2025 FAQs