收获:
两种方法
代码:
1.巧妙
#include<iostream>
#include<cstring>
using namespace std;
int main(){
string s1,s2,s;
cin>>s1>>s2;
if(s1.size()<s2.size()){
swap(s1,s2);
}
if((s1+s1).find(s2)==-1)
cout<<"false"<<endl;
else cout<<"true"<<endl;
return 0;
}
2.常规
记得将长度较大的放在前面
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
string s1,s2;
cin>>s1>>s2;
if(s1.size()<s2.size()) //将较大的放在前面
swap(s1,s2);
int flag=0;
string s=s1;
//reverse(s.begin(),s.end());
//cout<<s1<<endl<<s<<endl;
char c;
c=*(s1.begin());
s1.erase(s1.begin());
s1.append(1,c);
while(s1!=s)