-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathselfsimilarstrings.java
34 lines (32 loc) · 1.26 KB
/
selfsimilarstrings.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.io.*;
import java.util.*;
import java.math.*;
public class selfsimilarstrings {
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//BufferedReader in = new BufferedReader(new FileReader("input.txt"));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
String line = "";
while((line = in.readLine()) != null) {
int degrees = 0;
int length = 1;
boolean found = true;
while(length < line.length() && found) {
String temp = line;
ArrayList<String> checked = new ArrayList<>();
for(int i = 0; i <= temp.length() - length; i++) {
String sub = temp.substring(i, i + length);
if(checked.contains(sub)) continue;
int index = temp.indexOf(sub);
if(temp.lastIndexOf(sub) == index) found = false;
checked.add(sub);
}
//out.println(checked);
if(found) degrees++;
length++;
}
out.println(degrees);
}
out.close();
}
}