import java.util.HashMap;
import java.util.Map;
public class retazce {
public int prefixsufix(String retazec) {
int dlzka = retazec.length() - 1;
String s1;
String s2;
for (int j = 1; j < retazec.length(); j++) {
s1 = retazec.substring(0, dlzka - j + 1);
System.out.println(s1);
s2 = retazec.substring(j, dlzka + 1);
System.out.println(s2);
if (s1.equals(s2)) {
return dlzka - j + 1;
}
}
return 0;
}
public Map<Character, int[]> vytvorTabulkuSkokov(String s) {
Map<Character, int[]> mapa = new HashMap<Character, int[]>();
for (int i = 0; i < s.length(); i++) {
mapa.put(s.charAt(i), null);
}
for (Character ch : mapa.keySet()) {
int[] pole = new int[s.length()];
for (int j = 0; j < pole.length; j++) {
if (ch == s.charAt(j))
pole[j] = 0;
else
pole[j] = j + 1 - prefixsufix(s.substring(0, j) + ch);
}
mapa.put(ch, pole);
}
return mapa;
}
}
Spustac.java
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Spustac {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
retazce r = new retazce();
// System.out.println(r.prefixsufix("abaa"));
Map<Character, int[]> mapa = r.vytvorTabulkuSkokov("xyxyz");
for (Character ch : mapa.keySet()) {
System.out.println(ch + " " + Arrays.toString(mapa.get(ch)));
}
}
}