Pagini recente » Cod sursa (job #1532740) | Cod sursa (job #1383598) | Cod sursa (job #1532714) | Cod sursa (job #1112866) | Cod sursa (job #1745976)
#include <bits/stdc++.h>
using namespace std;
const int SMAX = 2000005;
char a[SMAX],
b[SMAX];
int pi[SMAX];
vector<int> matches;
int main(void) {
freopen("strmatch.in", "r", stdin);
freopen("strmatch.out", "w", stdout);
int t, l, ant;
gets(a + 1);
gets(b + 1);
pi[1] = 0;
ant = 0;
t = 0;
l = 1;
for(int i=2; a[i]; ++i) {
++l;
}
t = 0;
for(int i=1; b[i]; ++i) {
while(t && a[t+1]!=b[i])
t = pi[t];
if(a[t+1]==b[i])
++t;
if(t==l) {
t = pi[l];
++ant;
if(ant<=1000)
matches.push_back(i - l);
}
}
printf("%d\n",ant);
for(auto i:matches)
printf("%d ",i);
printf("\n");
fclose(stdin);
fclose(stdout);
return 0;
}