Cod sursa(job #1833289)

Utilizator Stefex09Stefan Teodorescu Stefex09 Data 22 decembrie 2016 01:14:34
Problema Potrivirea sirurilor Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ifstream in("strmatch.in");
    ofstream out("strmatch.out");

    string needle, haystack;
    in >> needle;
    in >> haystack;

    int pos = -1;
    vector<int> matches;

    do {
        pos = haystack.find(needle, pos + 1);
        if (pos != -1) {
            matches.push_back(pos);
        }
    } while (pos != -1);

    int toShow = min((int) matches.size(), 1000);
    out << matches.size() << "\n";
    for (int i = 0; i < toShow; i++) {
        out << matches[i] << " ";
    }

    in.close();
    out.close();

    return 0;
}