Cod sursa(job #2381886)

Utilizator AndreiVisoiuAndrei Visoiu AndreiVisoiu Data 17 martie 2019 13:57:16
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.55 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("abc2.in");
ofstream out("abc2.out");
const int MAX_LEN = 20000001;

map<string, bool> H;
string S, tmp;
int wordSize, cnt;

void match() {
    for(int i = 0, j = S.size()-wordSize; i < j; i++)  {
        tmp = S.substr(i, wordSize);
        if(H[tmp]) cnt++;
    }
}

int main()
{
    S.reserve(MAX_LEN);
    in >> S;
    in >> tmp;
    H[tmp] = 1;
    wordSize = tmp.size();
    while(in >> tmp)
        H[tmp] = 1;

    match();

    out << cnt << '\n';
    return 0;
}