Pagini recente » Profil dornescuvlad | Cod sursa (job #2389091) | Cod sursa (job #111141) | Cod sursa (job #1302113) | Cod sursa (job #2206971)
#include <fstream>
#include <string.h>
using namespace std;
char a[2000005], b[2000005];
int af[2000005];
int has, hbs, c=0;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
bool match(int i)
{
for(int j=0; j<strlen(b); j++)
if(b[j]!=a[j+i]) return 0;
return 1;
}
int main()
{
f>>b;
f>>a;
for(int i=0; i<strlen(b); i++)
{hbs=((hbs*256)+b[i])%101;
has=((has*256)+a[i])%101;}
for(int i=0; i<=strlen(a)-strlen(b); i++)
{
if(hbs==has)
if(match(i))
{c++; af[c]=i;}
has=((has+ 101-a[i]*((256%101)*256)%101)*256+a[i+strlen(b)])%101;
}
g<<c<<'\n';
for(int i=1; i<=c; i++) g<<af[i]<<" ";
return 0;
}