Pagini recente » Cod sursa (job #123705) | Cod sursa (job #2537776) | Cod sursa (job #2438136) | Cod sursa (job #580406) | Cod sursa (job #1815915)
#include <bits/stdc++.h>
using namespace std;
char s[4000005], Pi[4000005];
long long counter, raspuns[1001];
void KMP (int lungime, int n)
{
for (int i = 2; i<=n; ++i)
{
Pi[i] = Pi[i-1];
while (Pi[i] && s[Pi[i]+1] != s[i]) Pi[i] = Pi[Pi[i]];
if (s[i] == s[Pi[i]+1])
++Pi[i];
if (Pi[i] == lungime)
{
++counter;
if (counter <= 1000)
raspuns[counter] = i-2*lungime-1;
}
}
}
int main()
{
freopen ("strmatch.in", "r", stdin);
freopen ("strmatch.out", "w", stdout);
long long n, len;
cin >> (s+1);
len = strlen(s+1);
s[len+1] = '#';
cin >> (s+len+2);
n = strlen(s+1);
KMP(len, n);
cout << counter << '\n';
for (int i = 1; i<=counter && i <=1000; ++i)
cout << raspuns[i] << " ";
return 0;
}