Cod sursa(job #2473714)

Utilizator 0738076326Simon Wil 0738076326 Data 14 octombrie 2019 09:20:20
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>

using namespace std;

ifstream f("abc2.in");
ofstream g("abc2.out");

const int MOD = 7001;
typedef unsigned int ii;
vector <ii> v[MOD];
string s,st;
ii n,m,pos,put[35],ans;

inline void add(ii x){
    v[pos].push_back(x);
}

inline bool is(ii x){
    for(ii it: v[pos])
        if(it == x)
            return 1;
    return 0;
}

int main(){
    ii i,x;
    f >> s;
    put[0] = 1;
    for(i = 1 ; i <= 20 ; i++)
        put[i] = put[i - 1] * 3;

    f >> st;
    n = st.size();
    x = 0;
    for(i = 0 ; i < st.size() ; i++){
        x += put[i] * (st[i] - 'a');
    }
    if(!is(x))
        add(x);

    while(f >> st){
        x = 0;
        for(i = 0 ; i < st.size() ; i++){
            x += put[i] * (st[i] - 'a');
        }
        if(!is(x))
            add(x);
    }


    m = s.size();
    x = 0;
    for(i = 0 ; i < n - 1 ; i++){
        x += put[i] * (s[i] - 'a');
    }

    for(i = n - 1 ; i < m ; i++){
        x = x + (s[i] - 'a') * put[n - 1];
        if(is(x))
            ans++;
        x /= 3;
    }

    g << ans;
    return 0;
}