Cod sursa(job #3321943)

Utilizator alexiabortunBortun Alexia alexiabortun Data 11 noiembrie 2025 19:48:21
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <unordered_map>
#include <cstring>
using namespace std;
ifstream fin("abc2.in");
ofstream fout("abc2.out");

unordered_map <string, int> M;
unordered_map <string, int> M2;
#define N 10000001
string text, cuv;
int nr;
int main()
{
    fin >> text;
    while(fin >> cuv)
        if(M.find(cuv) == M.end())
            M[cuv] = 1;
    int lg = cuv.size();
    string s = text.substr(0, lg);
    if(M.find(s) != M.end())
        if(M2.find(s) == M2.end())
            M2[s] = 1;
        else M2[s]++;
    for(int i = lg; i < text.size(); i++)
    {
        s.erase(0, 1);
        s += text[i];
        if(M.find(s) != M.end())
            if(M2.find(s) == M2.end())
                M2[s] = 1;
            else M2[s]++;
    }
    int cnt = 0;
    for(auto per : M2)
        cnt += per.second;
    fout << cnt;
    return 0;
}