Binary string matching
Description
Given two 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 '000000' while the pattern string a is '11', you shoshould output 3, because the pattern A appeared at the posit
-
Input
-
The first line consist only one integer N, indicates n cases follows. in each case, there are two lines, the first line gives the string a, length (a) <= 10, and the second line gives the string B, length (B) <= 1000. and it is guaranteed that B is always longer than.
-
Output
-
For each case, output a single line consist a single integer, tells how many times do B appears as a substring of.
-
Sample Input
-
31110011101101011100100100100011010110100010101011
-
Sample output
-
303
#include <iostream>#include <string>using namespace std;int main(){ int n; cin>>n; while(n--) { string strA; string strB; int count = 0; cin>>strA; cin>>strB; int A = strA.size(); int B = strB.size(); for(int i=0; i<B; i++) { if(strB.substr(i, A) == strA) count ++; } cout<<count<<endl; } return 0;}
Binary string matching