Pagini recente » Cod sursa (job #1276110) | Cod sursa (job #289942) | Cod sursa (job #398980) | Cod sursa (job #1011446) | Cod sursa (job #1550133)
#include <fstream>
#include <cstring>
#define p 64
#define m1 100007
#define m2 100032
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char A[20000001],B[20000001],C[20000001];
int n,p1=1,p2=1,a1,b1,a2,b2,nr,na,nb,i;
int main()
{
fin>>A;
fin>>B;
na=strlen(A);
nb=strlen(B);
for(i=0;i<na;i++)
{
a1=(a1*p+A[i])%m1;
a2=(a2*p+A[i])%m2;
b1=(b1*p+B[i])%m1;
b2=(b2*p+B[i])%m2;
if(i!=0)
{
p1=(p1*p)%m1;
p2=(p2*p)%m2;
}
}
if(a1==b1 && a2==b2)
{
C[0]=1;
nr++;
}
for(i=na;i<=nb;i++)
{
b1=((b1-(B[i-na]*p1)%m1+m1)*p+B[i])%m1;
b2=((b2-(B[i-na]*p2)%m2+m2)*p+B[i])%m2;
if(a1==b1 && a2==b2)
{
C[i-na+1]=1;
nr++;
}
}
fout<<nr<<'\n';
for(i=0;i<=nb && i<=1000;i++)
if(C[i]==1)
fout<<i<<" ";
return 0;
}