String loop
Topic link: string ring
Title description
Problem solving ideas
Copy the two strings separately, and use the maximum value for brute force enumeration.
Note that the maximum substring will not exceed the original string.
code
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
string a,b;
int n1,n2,ans;
int main()
{
cin>>a>>b;
n1=a.size();
n2=b.size();
a+=a;
b+=b;
for(int i=0;i<n1*2;i++)
for(int j=0;j<n2*2;j++)
{
int k=0;
while(a[i+k]==b[j+k]&&i+k<2*n1&&j+k<2*n2) k++;
ans=max(ans,k);
}
cout<<min(ans,min(n1,n2));
}