bp算法
kmp算法
str.find(str2)函数
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string a,b;
cin >> a >> b;
if(a.size()<b.size()) swap(a,b);
for(int i = 0;i<a.size();i++)
{
a = a.substr(1)+a[0];
for(int j = 0;j+b.size()<=a.size();j++)
{
int k = 0;
for(;k<b.size();k++)
if(a[j+k]!=b[k]) break;
if(k == b.size())
{
cout << "true";
return 0;
}
}
}
cout << "false" << endl;
return 0;
}
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string a,b;
cin >> a >> b;
if(a.size()<b.size()) swap(a,b);
int len = a.size();
while (len--)
{
char first = a[0];
if (~a.find(b))
{
cout << "true" << endl;
return 0;
}
a = a.substr(1);
a = a + first;
}
cout << "false" << endl;
return 0;
}