Cod sursa(job #2430268)

Utilizator BogBBogdan BogB Data 13 iunie 2019 17:52:35
Problema Abc2 Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.05 kb
#include <iostream>
#include <unordered_set>
#include <string>

void find(int * k, std::string text, std::string cuvant)
{
    // Get the first occurrence
    size_t pos = text.find(cuvant);

    // Repeat till end is reached
    while( pos != std::string::npos)
    {
        // Add position to the vector
        *k = *k + 1;

        // Get the next occurrence from the current position
        pos = text.find(cuvant, pos + 1);
    }
}



int main() {

    int k = 0;
    FILE * fisier_out = fopen("abc2.out", "w");
    FILE * fisier_in = fopen("abc2.in", "r");

    char * text = (char*) malloc(10000000 * sizeof(char));
    std::string string_text;

    char buffer[23];
    std::string cuvant;
    std::unordered_set<std::string> mySet;

    fscanf(fisier_in, "%s", text);
    string_text = text;

    while(fscanf(fisier_in, "%s", buffer) != EOF){
        cuvant = buffer;
        mySet.insert(cuvant);
    }


    for( auto it = mySet.begin(); it != mySet.end(); it++) {

        find(&k, string_text , *it);

    }

    fprintf(fisier_out, "%d", k);
    return 0;
}