Pagini recente » Cod sursa (job #2450629) | Cod sursa (job #1458703) | tema | Cod sursa (job #2450630) | Cod sursa (job #2430268)
#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;
}