Pagini recente » Cod sursa (job #2931364) | Cod sursa (job #1858299) | Cod sursa (job #1133995) | Cod sursa (job #2432446) | Cod sursa (job #2969258)
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char a[2000001],b[2000001],la,lb;
ull n,sol[2000001];
#define M 100007
#define M1 100021
#define p 73
void citire()
{
fin>>a;
fin.get();
fin>>b;
la=strlen(a);
lb=strlen(b);
}
ull get_pow(int len) {
ull res = 1;
for (int i = 0; i < len; i++) {
res = (res * p) % M;
}
return res;
}
void rabinkarp()
{
ull ha=0,hb=0;
ull p1=get_pow(la-1);
for(ull i=0;i<la;i++){
ha=(ha*p+a[i])%M;
}
for(ull i=0;i<la;i++){
hb=(hb*p+b[i])%M;
}
if(la>lb)
{
fout<<0;
return;
}
//fout<<ha<<" "<<ha1<<" "<<hb<<" "<<hb1<<"\n";
if(ha==hb){
sol[0]=1;
n++;
}
// fout<<p<<" "<<p1<<" "<<p2<<"\n";
for(ull i=la;i<lb;i++)
{
hb=((hb-(b[i-la]*p1)%M+M)*p+b[i])%M;
if(ha==hb)
sol[i-la+1]=1,n++;
}
fout<<n<<"\n";
n=0;
for(ull i=0;i<lb && n<1000;i++)
if(sol[i]){
fout<<i<<" ";
n++;
}
}
int main()
{
citire();
rabinkarp();
return 0;
}