Cod sursa(job #2322198)

Utilizator alexge50alexX AleX alexge50 Data 17 ianuarie 2019 15:48:53
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.81 kb
/*
 *  Software sellers want to divide the users and conquer them, making each
 *  user agree not to share with others.
 *     - Richard Stallman
 */

#include <iostream>
#include <fstream>
#include <regex>

int main()
{
    std::ifstream fin("strmatch.in");
    std::string pattern;
    std::string text;

    fin >> pattern >> text;

    auto r = std::regex{"(?=(" + pattern + "))."};
    std::sregex_iterator next{text.cbegin(), text.cend(), r};
    std::sregex_iterator end;

    std::vector<long> positions;

    while (next != end && positions.size() < 1000)
    {
        std::smatch match = *next;
        positions.push_back(match.position());
        next++;
    }

    std::ofstream fout("strmatch.out");
    fout << positions.size() << std::endl;
    for(long pos: positions)
        fout << pos << " ";

    return 0;
}