Cod sursa(job #1591907)

Utilizator AndreiGrigorasAndrei Grigoras AndreiGrigoras Data 6 februarie 2016 20:47:47
Problema Potrivirea sirurilor Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.72 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

ifstream fin ( "strmatch.in" ) ;
ofstream fout ( "strmatch.out" ) ;

int main()
{
    string A , B ;
    size_t n , last = string :: npos ;
    vector<size_t> matches ;
    int pos = 0 ;
    n = B.find( A , pos ) ;
    while ( n != last )
    {
        matches.push_back(n) ;
        pos = n ;
        n = B.find( A , pos ) ;
    }
    fout << matches.size() << '\n' ;
    if ( matches.size() >= 1000 )
        for ( int i = 0 ; i <= 999 ; i++ )
            fout << matches[i] << ' ' ;
    else
        for ( vector<size_t> :: iterator it = matches.begin() ; it != matches.end() ; ++it )
            fout << *it << ' ' ;
    return 0;
}