Cod sursa(job #2180144)

Utilizator tomadimitrieDimitrie-Toma Furdui tomadimitrie Data 20 martie 2018 17:40:00
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>
#include <string>
#include <vector>

int main() {
    const std::string file = "strmatch";
    std::ifstream f(file + ".in");
    std::ofstream g(file + ".out");
    char *temp = (char*)malloc(sizeof(char) * 2000005);
    f.getline(temp, 200006);
    std::string what(temp);
    f.getline(temp, 200006);
    std::string in(temp);
    free(temp);
    int nr = 0;
    size_t pos = in.find(what, 0);
    std::vector<size_t> vpos;
    while (pos != std::string::npos) {
        vpos.push_back(pos);
        nr++;
        pos = in.find(what, pos + 1);
    }
    g << nr << std::endl;
    for (auto const& i: vpos) {
        g << i << " ";
    }
    g << std::endl;
    f.close();
    g.close();
}