Cod sursa(job #503353)

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

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


const int MAX_SOL = 1000;
const int MAX_BUF = 2000005;

char buff[MAX_BUF];

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

    assert(scanf("%s", buff) == 1);
    string needle(buff);
    assert(scanf("%s", buff) == 1);
    string hay(buff);

    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 << " ";
    }
}