Cod sursa(job #2297052)

Utilizator mircearoataMircea Roata Palade mircearoata Data 5 decembrie 2018 11:16:22
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda prega_casi_5.12.2018 Marime 1.14 kb
#include <cstdio>
#include <string>
#include <cstring>
#include <unordered_set>

using namespace std;

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

int cnt, n, len, ans;
char ch2[10000001];
string ch;
string cuv;
unordered_set<string> dictionary;

int main()
{
    //ios_base::sync_with_stdio(false);
    freopen("abc2.in", "r", stdin);
    freopen("abc2.out", "w", stdout);
    fgets(ch2, 10000000, stdin);
    ch2[strlen(ch2) - 1] = '\0';
    ch = string(ch2);
    //getline(in, ch);
    while(fgets(ch2, 20, stdin))
    {
        //getline(in, cuv);
        ch2[strlen(ch2) - 1] = '\0';
        cuv = string(ch2);
        n = max(n, (int)cuv.length());
        dictionary.insert(cuv);
    }
    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());
    }
    printf("%d", ans);
    return 0;
}