Test instructions: Gives a string that repeats the maximum length of the string and repeats the number of repetitions (in length), when there are two lengths of the same substring that are the output dictionary order small substring.
Example: Gagagag maximum repeat substring is gagag number of times is 2
Analysis: Two points + violence map
Determine whether a string of length k has a repeating string, the existence of a longer string is discussed, and a shorter string is discussed if it does not exist.
Time:160ms (SKY)
#include <bits/stdc++.h> using namespace std;
int t;
String str,s;
int Len;
unordered_map<string,int>temp;
set<string>check;
int judge (int mid)//Determine if there is a duplicate string {temp.clear ();
Check.clear ();
for (int j=0; j<=len-mid; J + +) {s=str.substr (j,mid);
temp[s]++;
if (temp[s]==2) {Check.insert (s);
}} if (Check.empty () ==0) {return 1;
} return 0;
} int main () {Ios::sync_with_stdio (false);
Cin.tie (0);
Cout.tie (0);
cin>>t;
while (t--) {temp.clear ();
Check.clear ();
cin>>str;
Len=str.size ();
int left=1,right=len-1;//binary finds the length of the string while (right-left>3) {int mid= (left+right)/2;
if (judge (mid)) {Left=mid;
} else {right=mid;
}} int ans=left; for (int i=left; i<=righT
i++) {if (judge (i)) {ans=i; }} int K=judge (ANS);//Determine length ans for maximum length if (Check.empty () ==1) {cout<< "No rep Etitions found! "
<<endl; } else {s=*check.begin ();//set containers are sorted from small to large, with the smallest beginning cout<<s<< "" <<
temp[s]<<endl;
}} return 0;
}