Cod sursa(job #2008356)

Utilizator IsacLucianIsac Lucian IsacLucian Data 6 august 2017 12:42:42
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.9 kb
#include <bits/stdc++.h>
#define P 777013

using namespace std;

ifstream fin("abc2.in");
ofstream fout("abc2.out");

char a[10000002],aux[22];
int n,m;
vector<int>h[P];

void Citire()
{
    int i,c,x;
    fin>>(a+1);
    m=strlen(a+1);
    fin.get();
    while(fin>>(aux+1))
    {
        n=strlen(aux+1);
        c=0;
        for(i=1;i<=n;i++)
            c=(c*10+aux[i]-'a'+1)%P;

        x=c%P;
        if(h[x].empty())h[x].push_back(1);
        fin.get();
    }
}

void Rezolva()
{
    int i,j,c,cnt,x;
    cnt=0;
    for(i=n;i<=m;i++)
    {
        c=0;
        for(j=i-n+1;j<=i;j++)
            c=(c*10+a[j]-'a'+1)%P;

        x=c%P;
        if(!h[x].empty())
        {
            cnt++;
            h[x].pop_back();
        }
    }
    fout<<cnt<<"\n";
}

int main()
{
    Citire();
    Rezolva();
    fin.close();
    fout.close();
    return 0;
}