Cod sursa(job #2297059)

Utilizator mircearoataMircea Roata Palade mircearoata Data 5 decembrie 2018 11:29:55
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda prega_casi_5.12.2018 Marime 0.85 kb
#include <fstream>
#include <string>
#include <unordered_map>

using namespace std;

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

int cnt, n, len, ans;
string ch;
string cuv;
unordered_map<string, int> dictionary;

int main()
{
    ios_base::sync_with_stdio(false);
    getline(in, ch);
    while(!in.eof())
    {
        getline(in, cuv);
        n = max(n, (int)cuv.length());
        dictionary[cuv] = 1;
    }
    len = ch.length();
    for(int i = 0; i < len - n + 1; i++)
    {
        char temp[21] = {'\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0'};
        for(int j = 0; j < n; j++)
            temp[j] = ch[i+j];
        string str(temp);
        ans += (dictionary.find(str) != dictionary.end());
    }
    out << ans;
    return 0;
}