描述
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 ‘1001110110’ while the pattern string A is ‘11’, you should output 3, because the pattern A appeared at the posit
3 11 1001110110 101 110010010010001 1010 110100010101011
3 0 3
#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; }
原文:http://www.cnblogs.com/imwtr/p/4069407.html