import java.util.*;
class Gataca {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int caseNum;
caseNum = scn.nextInt();
String dna ="";
scn.nextLine();
for(int i = 0; i < caseNum; i++) {
dna = scn.nextLine();
int len = dna.length();
if(len > 1000) continue;
String greater = null;
int occur = 0;
for (int j= len-1; j > 0; j--) {
/// panjang substring
ArrayList<String> arlSub = new ArrayList<String>();
int tmpOcc = 0;
String gTmp = "";
for (int k = 0; (k+j) <= len; k++) {
String sub = dna.substring(k,k+j);
if(!arlSub.isEmpty()) {
if(arlSub.indexOf(sub) > 0) {
continue;
}
}
arlSub.add(sub);
int start = k;
int ocrTmp = 0;
while(start != -1) {
ocrTmp++;
start = dna.indexOf(sub, start +1);
}
if(ocrTmp >= tmpOcc) {
tmpOcc = ocrTmp;
gTmp = sub;
}
}
if(tmpOcc > 1) {
greater = gTmp;
occur = tmpOcc;
break;
}
}
if(occur > 1) {
System.out.println(greater + " " + occur);
} else {
System.out.println("No repetitions found!");
}
}
}
}
0 comments:
Post a Comment
Please leave a comment