给定两个字符串s1和s2,如果能通过s1循环移位,使s2包含在s1中,那么我们就说s2 是s1的亲和串。S1+S1后进行查找即可
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s1,s2;
while(cin>>s1)
{
cin>>s2;
s1=s1+s1;
int ans=s1.find(s2);
if(ans!=-1) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
本文介绍了一种简单有效的算法,用于判断一个字符串是否为另一个字符串的亲和串。通过将目标字符串翻倍并使用字符串查找功能,可以快速确定源字符串是否包含目标字符串的一种循环排列。
1139

被折叠的 条评论
为什么被折叠?



