Cod sursa(job #2206965)

Utilizator VNohaiNohai Vlad-Auras VNohai Data 24 mai 2018 17:15:05
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
#include <string.h>
using namespace std;
char a[2000000], b[2000000];
int has, hbs;
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))
    g<<i<<" ";
    has=((has+ 101-a[i]*((256%101)*256)%101)*256+a[i+strlen(b)])%101;
    }
    return 0;
}