I thought that I did solved the problem Oulipo http://poj.org/problem?id=3461 , but I have RuntimeError in my solution and I can’t to solve the problem. Why my solution is wrong? an idea to improve my solution?
Here is the code
(Thanks!)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int cant = in.nextInt();
in.nextLine();
for (int i = 0; i < cant; i++) {
int cont = 0;
String co = in.nextLine();
String pal = in.nextLine();
char let = co.charAt(0);
int l1 = co.length();
int l2 = pal.length();
for (int j = 0; j < l2 - l1 + 1; j++) {
boolean es = true;
boolean es1 = true;
if (pal.charAt(j) == let) {
int k;
int nuevoind = 0;
int pAux = 0;
for (k = 0; k < l1; k++) {
if (k > 0) {
if ((pal.charAt(j + k) == co.charAt(nuevoind))) {
nuevoind++;
pAux = k;
es1 = true;
} else {
nuevoind = 0;
es1 = false;
}
}
if (pal.charAt(j + k) != (co.charAt(k))) {
es = false;
if (es1) {
j = j + pAux;
}
break;
}
}
if (!es) {
j = j + pAux-1;
}
if (es) {
cont++;
}
}
}
System.out.println(cont);
}
}
}