Cod sursa(job #2207086)

Utilizator VNohaiNohai Vlad-Auras VNohai Data 24 mai 2018 20:57:50
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.76 kb
#include <fstream>
#include <string.h>
using namespace std;
char a[2000005], b[2000005];
int af[2000005];
int has1, has2, hbs1, hbs2, c=0;
ifstream f("strmatch.in");
ofstream g("strmatch.out");

int main()
{
    f>>b;
    f>>a;
    for(int i=0; i<strlen(b); i++)
    {hbs1=((hbs1*73)+b[i])%100007;
     hbs2=((hbs2*73)+b[i])%100021;
     has1=((has1*73)+a[i])%100007;
     has2=((has2*73)+a[i])%100021;}
    for(int i=0; i<=strlen(a)-strlen(b); i++)
    {
    if(hbs1==has1 && hbs2==hbs2)
    {c++; af[c]=i;}
    has1=((has1+100007-a[i]*((73%100007)*73)%100007)*73+a[i+strlen(b)])%100007;
    has2=((has2+100021-a[i]*((73%100021)*73)%100021)*73+a[i+strlen(b)])%100021;
    }
    g<<c<<'\n';
    for(int i=1; i<=c; i++) g<<af[i]<<" ";
    return 0;
}