Pagini recente » Cod sursa (job #2400909) | Cod sursa (job #879591) | Cod sursa (job #1702614) | Cod sursa (job #99259) | Cod sursa (job #3242272)
//package strmatch;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
public class Main {
static final String INPUT_FILE = "strmatch.in";
static final String OUTPUT_FILE = "strmatch.out";
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new FileReader(INPUT_FILE));
PrintWriter writer = new PrintWriter(OUTPUT_FILE);
solve(reader, writer);
reader.close();
writer.flush();
writer.close();
}
public static void solve(BufferedReader reader,
PrintWriter writer) throws IOException {
String a = reader.readLine();
String b = reader.readLine();
StringMatchingStrategy strategy = new BruteForceStrategy();
List<Integer> match = strategy.match(a, b);
writer.println(match.size());
for (int i = 0; i < Math.min(1000, match.size()); ++i) {
writer.write(match.get(i) + " ");
}
}
public interface StringMatchingStrategy {
List<Integer> match(String a, String b);
}
public static class BruteForceStrategy implements StringMatchingStrategy {
@Override
public List<Integer> match(String a, String b) {
List<Integer> result = new ArrayList<>();
int it = b.indexOf(a);
while (it != -1) {
result.add(it);
it = b.indexOf(a, it + 1);
}
return result;
}
}
}