运用从string中的find()函数
AC代码
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
int n,count;
string a,b;
cin>>n;
while(n--)
{
cin>>a>>b;
count=0;
size_t fi=b.find(a,0);
while(fi!=b.npos)
{
count++;
fi=b.find(a,fi+1);
}
cout<<count<<endl;
}
return 0;
}
b.find(a)的含义为在b串中查找a串开始的位置。
若未找到,返回npos。
b.find(a,0)的含义为从b串的第0个位置起,查找a串开始的位置。若未找到,返回npos。
b.npos的含义为某位置在b中不存在