Pagini recente » Cod sursa (job #2089011) | Cod sursa (job #2127022) | Cod sursa (job #1400365) | Cod sursa (job #2547777) | Cod sursa (job #2547669)
#include <fstream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#include <map>
#include <string.h>
#include <queue>
#include <stack>
#define INF 0x3f3f3f3f
using namespace std;
#ifdef DEBUG
string name = "data";
#else
string name = "prefix";
#endif
ifstream fin(name + ".in");
ofstream fout(name + ".out");
int n;
string s;
int pi[1000000];
void solve() {
fin >> s;
memset(pi, 0, sizeof(pi));
int j = 0;
int startMatch = -1;
int i = 1;
int best = 0;
while (i <= s.size()) {
if (s[i] == s[j]) {
if (startMatch == -1) {
startMatch = i;
}
j++;
pi[i] = j;
i++;
} else {
if (startMatch > 0) {
if (startMatch <= (i - startMatch)) {
best = max(best, i - (i % startMatch));
}
startMatch = -1;
}
if (j == 0) {
i++;
} else {
j = pi[j - 1];
}
}
}
fout << best << "\n";
}
int main() {
fin >> n;
for (int i = 0; i < n; ++i) {
solve();
}
return 0;
}