#include #include #include using namespace std; int N; char *text; bool suffixCompare( int a, int b ) { int i; for (i=0; (ib; } else { return (text[a+i] < text[b+i]); } } int main() { int n; cin >> n; while (n--) { string input; cin >> input; text = const_cast(input.c_str()); N = input.length(); int *SA = new int[N]; for (int i=0; imaxLen) { maxLen = k; maxStart = SA[i]; } } int lastPos=0; string s = input.substr(maxStart, maxLen); while ((lastPos=input.find(s,lastPos))!=string::npos) { maxFreq++; lastPos++; } /* // brute-force method - too slow! for (int i=0; i=2) { maxStart = i; maxLen = j; maxFreq = freq; } } } */ if (maxLen>0) { cout << input.substr(maxStart,maxLen) << " " << maxFreq << endl; } else { cout << "No repetitions found!" << endl; } delete[] SA; } return 0; }