Pagini recente » Rating Black Crow (blackcrow13) | Monitorul de evaluare | Cod sursa (job #1176692) | IOIT_CAZAN_137TESLA | Cod sursa (job #1162291)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int NMAX = 2000005;
int N,M,i,q,pi[NMAX],S[1005],sol;
char A[NMAX],B[NMAX];
int main()
{
freopen("strmatch.in","r",stdin);
freopen("strmatch.out","w",stdout);
scanf("%s",A+1); N=strlen(A+1);
scanf("%s",B+1); M=strlen(B+1);
for(i=2;i<=N;i++)
{
while(q && A[i]!=A[q+1]) q=pi[q];
if(A[i]==A[q+1]) q++;
pi[i]=q;
}
for(q=0,i=1;i<=M;i++)
{
while(q && B[i]!=A[q+1]) q=pi[q];
if(B[i]==A[q+1]) q++;
if(q==N)
{
sol++;
if(sol<=1000) S[sol]=i-N;
}
}
printf("%d\n",sol);
for(i=1;i<=min(sol,1000);i++) printf("%d ",S[i]);
return 0;
}