Pagini recente » Cod sursa (job #1236959) | Cod sursa (job #810041) | Cod sursa (job #3228535) | Cod sursa (job #1376314) | Cod sursa (job #3274562)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
int n, i, j, lung[4000002];
vector<int> rasp;
string a, b;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
fin >> a >> b;
b = a + "@" + b;
n = b.size();
j = 0;
for(i = 1; i < n; i++) {
while(0 < j && b[j] != b[i]) j = lung[j - 1];
if(b[j] == b[i]) j++;
lung[i] = j;
if(lung[i] == a.size()) rasp.push_back(i - a.size() + 1);
}
int nrMax = min((int)rasp.size(), 1000);
fout << nrMax << "\n";
for(i = 0; i < nrMax; i++) {
fout << rasp[i] - (a.size() + 1) << " ";
}
return 0;
}