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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
voila le code qu ej'ai fait mais un pb
public static void main(String[] args) {
ArrayList A = new ArrayList();
A.add("a");
A.add("x");
A.add("c");
A.add("h");
A.add("d");
A.add("v");
ArrayList B = new ArrayList();
B.add("ah");
B.add("ac");
B.add("ad");
ArrayList SS = new ArrayList();
ArrayList c = new ArrayList();
ArrayList T = new ArrayList();
for (int i = 0; i < B.size(); i++) {
String Q2 = B.get(i).toString();
for (int j= i+1; j < B.size(); j++) {
String Q1 = B.get(j).toString();
char[] chars = Q1.toCharArray();
StringBuffer buf = new StringBuffer();
int m = chars.length;
for (int E = 0; E < m; E++) {
buf.append(chars[E]);
for (int W = 0, n = buf.length(); W < n; W++) {
if (A.contains(buf.substring(W, buf.length()))) {
c.add(buf.substring(W, buf.length()));
buf = new StringBuffer();
W = n;
}
}
}
}
ArrayList AToDelete = new ArrayList();
int u = 0;
int index;
Iterator ii = c.iterator();
while (ii.hasNext()) {
String x = ii.next().toString();
index = Q2.lastIndexOf(x); //on recherche le dernier index où l'on trouve la chaine 1;
if (index != -1) { // on a trouvé
AToDelete.add(c.get(u));
}
u++;
}
c.removeAll(AToDelete);
Iterator f = c.iterator();
while (f.hasNext()) {
String x = f.next().toString();
String o = Q2.concat(x);
SS.add(o);
}
}
System.out.println(SS);
} |
Partager