Cod sursa(job #503349)

Utilizator wefgefAndrei Grigorean wefgef Data 22 noiembrie 2010 18:01:03
Problema Potrivirea sirurilor Scor 40
Compilator cpp Status done
Runda Arhiva educationala Marime 0.64 kb
#include <cassert>
#include <cstdio>

#include <iostream>
#include <string>
#include <vector>
using namespace std;


const int MAX_SOL = 1000;

int main() {
    assert(freopen("strmatch.in", "r", stdin));
    assert(freopen("strmatch.out", "w", stdout));

    string needle, hay;
    cin >> needle >> hay;

    int no_sol = 0, pos = -1;
    vector<int> match;
    while ((pos = hay.find(needle, pos + 1)) != string::npos) {
        if (++no_sol <= MAX_SOL) {
            match.push_back(pos);
        }
    }

    cout << no_sol << "\n";
    for (vector<int>::iterator it = match.begin(); it != match.end(); ++it) {
        cout << *it << " ";
    }
}