Pagini recente » Cod sursa (job #2790216) | Cod sursa (job #742725) | Cod sursa (job #1732295) | Rating Jones Clifford Mihnea (jonesmihnea) | Cod sursa (job #2023846)
#include <bits/stdc++.h>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
string A,B;
vector <int> rez;
int baza=73;
int MOD2=100000007;
int MOD=666013;
int hashA,hashB,hashB2,hashA2,cnt;
int main()
{
f>>A>>B;
int putere=1,i;
for(i=0; i<A.size(); i++)
{
hashA += (A[i]*putere) % MOD;
hashA2 += (A[i]*putere) % MOD2;
putere *= baza;
}
putere=1;
for(i=0; i<A.size(); i++)
{
hashB += (B[i]*putere) %MOD;
hashB2 += (B[i]*putere) %MOD2;
putere *= baza;
}
if(hashA==hashB&&hashA2==hashB2)
{
cnt++;
rez.push_back(i-A.size()+1);
}
putere/=baza;
for(i=A.size(); i<B.size(); i++)
{
hashB/=baza%MOD;
hashB+=B[i]*putere%MOD;
hashB2/=baza%MOD2;
hashB2+=B[i]*putere%MOD2;
if(hashA==hashB && hashA2==hashB2)
{
cnt++;
if(cnt<=1000)
rez.push_back(i-A.size()+1);
}
}
g<<cnt<<'\n';
for(auto it:rez)
g<<it<<" ";
return 0;
}