标签:
3 11 1001110110 101 110010010010001 1010 110100010101011
3 0 3
分析:这道题用strstr函数
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main() { int test,n; char a[100],b[1000]; cin>>test; while(test--) { cin>>a>>b; char *p; p=b; int count=0; while(p=strstr(p,a)) { p=p+1; count++; } printf("%d\n",count); } return 0; }
#include<iostream> #include<stdio.h> #include<string.h> using namespace std; int main() { string a,b; int n; cin>>n; while(n--) { cin>>a>>b; int pos=b.find(a,0); int count=0; while(pos!=string::npos) { count++; pos=b.find(a,pos+1); } printf("%d\n",count); } return 0; }
NYOJ题目5---Binary String Matching
标签:
原文地址:http://blog.csdn.net/qq_qingtian/article/details/44757655