Cod sursa(job #1314383)

Utilizator MacWonkMihai Alexandru Cosmin MacWonk Data 11 ianuarie 2015 20:10:42
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.82 kb
#include <fstream>
#include <cstring>
#include <algorithm>
using namespace std;
ifstream f("abc2.in");
ofstream g("abc2.out");
int l,lcuv,i,j,k,rez;
long long hash;
long long a[50003];
char sir[10000005];
char aux[21];
int main()
{
    f.getline(sir,10000005);
    l=strlen(sir);
    while(f.getline(aux,21))
    {
        lcuv=strlen(aux);
        hash=0;
        for(i=0;i<lcuv;++i)
        {
            hash=aux[i]-'a'+1;
            if(i!=lcuv-1) hash*=3;
        }
        ++k;
        a[k]=hash;
    }
    sort(a+1,a+1+k);
    for(i=0;i<l-lcuv+1;++i)
    {
        hash=0;
        for(j=i;j<=i+lcuv-1;++j)
        {
            hash=aux[i]-'a'+1;
            if(j!=i+lcuv-1) hash*=3;
            if(binary_search(a+1,a+1+k,hash)) ++rez;
        }
    }
    g<<rez<<'\n';
    return 0;
}