Cod sursa(job #1594139)

Utilizator superstar1998Moldoveanu Vlad superstar1998 Data 9 februarie 2016 11:12:23
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#define mod 666013
using namespace std;
char *s,*c[50001];
int n,a,b,k;
vector<char*> H[mod];
ifstream f("abc2.in");
ofstream g("abc2.out");
int cod(char* s)
{
    int y=0;
    for(int i=0;i<b;i++)
        y=(y*10+s[i]-'a'+1)%mod;
    return y;
}
bool comp(char* x, char* y)
{
    int i=0;
    while(i<b&&x[i]==y[i])i++;
    if(i==b)return true;
    return false;
}
bool cauta(char* s, int k)
{
    for(unsigned int i=0;i<H[k].size();i++)
        if(comp(H[k][i],s)) return true;
    return false;
}
void adauga(int k)
{
    int y=cod(c[k]);
    if(!cauta(c[k],y))
        H[y].push_back(c[k]);
}
bool verif(int i)
{
    int y=cod(s+i);
    return cauta(s+i,y);
}
int main()
{
    s=new char[10000001];
    f>>s;
    a=strlen(s);
    n=1;
    c[1]=new char[21];
    f>>c[1];
    b=strlen(c[1]);
    adauga(1);
    while(c[++n]=new char[21],f>>c[n])
    {
        adauga(n);
    }
    n--;
    for(int i=0;i<=a-b;i++)
        if(verif(i))k++;
    g<<k;
    return 0;
}