Cod sursa(job #1761349)

Utilizator eu3neuomManghiuc Teodor-Florin eu3neuom Data 22 septembrie 2016 08:58:32
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int NMax = 5005;

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

int main(){

    ios::sync_with_stdio(false);
    fin.tie(NULL);

    string s, a;
    fin >> s >> a;

    int n = s.size();
    int m = a.size();

    if(n < m){
        cout << 0;
        return 0;
    }

    string aux;
    unordered_map < ll, int > uMap;
    ll x = 0;
    for(int i = 0; i <= n - m; i++){

        x = 0;

        for(int j = 0; j < m; j++){

            if(s[i + j] == 'a') x += 0;
            if(s[i + j] == 'b') x += 1;
            if(s[i + j] == 'c') x += 2;

            x *= 3;

        }

        uMap[x]++;

    }

    int ans = 0;
    x = 0;
    for(int j = 0; j < m; j++){

        if(a[j] == 'a') x += 0;
        if(a[j] == 'b') x += 1;
        if(a[j] == 'c') x += 2;

        x *= 3;

    }

    ans += uMap[x];
    uMap[x] = 0;

    while(fin >> a){

        x = 0;

        for(int j = 0; j < m; j++){

            if(a[j] == 'a') x += 0;
            if(a[j] == 'b') x += 1;
            if(a[j] == 'c') x += 2;

            x *= 3;

        }

        ans += uMap[x];
        uMap[x] = 0;

    }

    fout << ans;

    return 0;

}