解析
字符串的操作,可以用函数解决这个问题
s
2.
f
i
n
d
(
s
1.
s
u
b
s
t
r
(
i
,
j
)
)
s2.find~(s1.substr~(i,~j))
s2.find (s1.substr (i, j))
在s2中查找s1中
i
i
i到
j
j
j第一次出现的位置
substr是C++语言函数,主要功能是复制子字符串,要求从指定位置开始,并具有指定的长度。如果没有指定长度_Count或_Count+_Off超出了源字符串的长度,则子字符串将延续到源字符串的结尾。
Code
#include <bits/stdc++.h>
using namespace std;
int len1, len2, ans;
string te, tr, s1, s2;
int main ()
{
cin >> te >> tr;
s1 = te + te; s2 = tr + tr;
len1 = s1.length (); len2 = s2.length ();
if (len1 < len2)
{
swap (s1, s2);
int t = len1; len1 = len2, len2 = t;
}
for (int i = 0; i < len1 / 2; ++ i)
for (int j = 1; j <= len2 / 2; ++ j)
{
int f = s2.find (s1.substr (i, j));
if (f != -1)
if (j > ans)
ans = j;
}
cout << ans << endl;
return 0;
}