[Ybtoj High-efficiency Advanced 2.1] [String] String ring
topic
Problem-solving ideas
Accumulate the string itself
and intercept a section of it to
find whether another string contains the
maximum output length
Code
#include <iostream>
#include <cstdio>
#include <cstdio>
using namespace std;
string x, y;
int lx, ly, ans;
int main() {
cin >> x >> y;
x = x + x;
y = y + y;
lx = x.size();
ly = y.size();
for (int i = 0; i < lx; i++)
for (int j = 1; j < min(lx - i + 1, ly); j++) {
string s = x.substr(i, j);
if (y.find(s) != -1)
ans = max(ans, j);
}
cout << ans;
return 0;
}