Pagini recente » Borderou de evaluare (job #1179450) | Cod sursa (job #3161642)
using namespace std;
#include<iostream>
#include<fstream>
#include<cstring>
ifstream fin("prefix.in");
ofstream fout("prefix.out");
int t, l;
char s[1000005], a[1000005];
int lps[1000005];
int main() {
fin >> t;
while (t--) {
fin >> s;
strcpy(a+1, s);
l = strlen(a+1);
lps[1] = 0;
// cout << lps[1] << "\n";
int k = 0, maxim = 0;
for (int i = 2; i<=l; i++) {
while (k != 0 && a[i] != a[k+1]) {
k = lps[k];
}
if (a[k+1] == a[i]) {
k++;
}
lps[i] = k;
//cout << lps[i] << " ";
if (k > 0 && i % (i-k) == 0) {
cout << i;
maxim = max(maxim, i);
}
// cout << "\n";
}
fout << maxim << "\n";
}
return 0;
}