Cod sursa(job #2472466)

Utilizator 3DwArDPauliuc Edward 3DwArD Data 12 octombrie 2019 13:39:10
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <bits/stdc++.h>
using namespace std;
#define NMAX 300005
#define ull unsigned long long
ifstream f("abc2.in");
ofstream g("abc2.out");
ull code(string a){
    ull pw = 1;
    ull ans =0 ;
    for(char c:a)
    {
        ans=ans+(c-'a')*pw;
        pw*=3;
    }
    return ans;
}
int main()
{
   // freopen("in", "r", stdin);
    //ios_base::sync_with_stdio(false);
    string s;
    f>>s;
    map<int, int> cuvinte;
    string x;
    int lg;
    while(f>>x){
        lg =x.size();
        cuvinte[code(x)]++;
    }
    int ans=0;
    for(int i=0;i<=s.size()-lg;i++)
        if(cuvinte[code(s.substr(i,lg))])ans++;
    g<<ans;
    return 0;
}