题目大意
给出一个长字符串与一个短的字符串,求短字符串在长字符串内出现了多少遍
题目分析
这种题目就十分能体现 C + + C++ C++的优势了,我们可以使用 f i n d find find函数直接 A C AC AC
C o d e Code Code
#include<iostream>
#include<cstdio>
using namespace std;
string a,b;
int tmp=0,ans=0;
int main(){
cin>>a>>b;
while((tmp=a.find(b,tmp))!=string::npos){
tmp+=1;
++ans;
}
printf("%d",ans);
return 0;
}