Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Main {
- public static int lcp(String str1, String str2) {
- int count = 0;
- for (int i = 0; i < Math.min(str1.length(), str2.length()); i++) {
- if (str1.charAt(i) == str2.charAt(i)) count++;
- else break;
- }
- return count;
- }
- public static void main (String[] args) {
- Scanner s = new Scanner(System.in);
- String[] sa;
- int n = s.nextInt();
- String str;
- int count;
- for (int i = 0; i < n; i++) {
- str = s.next();
- sa = new String[str.length()];
- for (int j = 0; j < str.length(); j++) {
- sa[j] = str.substring(j);
- }
- Arrays.sort(sa);
- count = 0;
- count += sa[0].length() + 1;
- for (int j = 0; j < str.length() - 1; j++) {
- count += sa[j+1].length() - lcp(sa[j], sa[j+1]);
- }
- System.out.println(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement