您的位置:首页 > 其它

南阳理工学院 Binary String Matching

2018-01-28 09:12 330 查看
运用从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中不存在
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: