垃圾
2023-05-13 19:26:38
发布于:江苏
67阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
int x, y, len, len1, len2, ans=0, max=0;
cin>>s1>>s2;
len1 = s1.size();
len2 = s2.size();
max = min(len1, len2);
s1 += s1;
s2 += s2;
for(int i=1; i<=len1; i++){
for(int j=1; j<=len2; j++){
len = 0;
x = i;
y = j;
while(len<max && s1[x++]==s2[y++])
len++;
if (len > ans)
ans = len;
}
}
cout<<ans<<endl;
return 0;
}
这里空空如也
有帮助,赞一个