Binary String matching time limit:MS | Memory limit:65535 KB Difficulty:3
-
Describe
-
Given Strings A and B, whose alphabet consist only ' 0 ' and ' 1 '. Your task is-only to-tell how many times does A appear as a substring of B? For example, the text string B is ' 1001110110 ' and the pattern string A is ' one ', you should output 3, because the patter N A appeared
at the posit
-
-
Input
-
The first line consist only one
-
integer n, indicates n cases follows. In each case, there is lines, the first line gives the string A, Length (a) <=, and the second line gives the S Tring B, Length (b) <= 1000. And it is guaranteed this B is always longer than A.
-
-
Output
-
-
for each case, the output a single line consist a single integer, tells how the many times do B appears as a substring of a.
-
-
Sample input
-
-
-
-
Sample output
-
1 2#include <iostream>3#include <string>4 using namespacestd;5 intMain ()6 {7 stringb;8 intN;cin>>N;9 while(n--)Ten { OneCin>>a>>b; A intCount=0; -UnsignedintNum=b.find (A,0); - while(num!=string:: NPOs) the { -count++; -Num=b.find (a,num+1); - } +cout<<count<<Endl; - } + } A
Nyoj 5 Binary String Matching