Cod sursa(job #1690834)

Utilizator Aavatar36Russu Vadim Aavatar36 Data 15 aprilie 2016 21:57:26
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
#include <fstream>
#include <string>
#include <vector>

std::ifstream fin("strmatch.in");
std::ofstream fout("strmatch.out");

std::vector<size_t> KMP(std::string needle, std::string hatch) {
	std::size_t pos = hatch.find(needle);
	std::vector<std::size_t> results;
	while (1) {
		if (pos == std::string::npos) {
			break;
		}
		else {
			if (results.size() < 1000) {
				results.push_back(pos);
			}
		}
		pos = hatch.find(needle, pos + 1);
	}
	return results;
}

int main() {
	std::string a, b;
	fin >> a >> b;
	std::vector<size_t> res = KMP(a, b);
	fout << res.size() << "\n";
	for (std::vector<size_t>::iterator it = res.begin(); it != res.end(); it++) {
		fout << *it << " ";
	}
	return 0;
}