Cod sursa(job #2447698)

Utilizator Alex18maiAlex Enache Alex18mai Data 14 august 2019 12:29:10
Problema Potrivirea sirurilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.06 kb
//ALEX ENACHE

#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>

using namespace std;

//-----------------------------------------------------------------

#include <fstream>

//ifstream cin("input"); ofstream cout("output");
ifstream cin("strmatch.in"); ofstream cout("strmatch.out");

int kmp[4000100];
vector < int > ans;

int main() {

	string a, b, s;
	cin >> a >> b >> s;

	cin >> a >> b;
	s = '#' + a + '#' + b;

	int cont = 0;

	for (int i = 2; i < s.size(); i++) {
		int now = kmp[i - 1];
		while (now != 0 && s[now + 1] != s[i]) {
			now = kmp[now];
		}
		if (s[now + 1] == s[i]) {
			now++;
		}
		kmp[i] = now;
		if (now == a.size()) {
			cont++;
			if (ans.size() < 1000) {
				ans.push_back(i-2*a.size()-1);
			}
		}
	}

	cout << cont << '\n';
	for (auto& x : ans) {
		cout << x << " ";
	}


	return 0;
}