Cod sursa(job #2855242)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 22 februarie 2022 11:22:03
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.17 kb
#include <fstream>
#include <deque>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cstring>
#include <climits>

#define MOD 104659

using namespace std ;

ifstream cin ("strmatch.in") ;
ofstream cout ("strmatch.out") ;

string a, b, rest ;

void aflarest()
{
    string auxa = a ;

    for(int f = 1 ; f < a.size() ; f ++)
    {
        string st = a.substr(0, f) ;
        string dr = a.substr(a.size() - f, a.size() - 1) ;

        if(st == dr)rest = a.substr(f, a.size() - 1) ;
    }
}

vector<int> rez ;

bool incaunul(char *ptr)
{
    for(int f = 0 ; f < rest.size() ; f ++)
        if(ptr[f] != rest[f])return 0 ;

    rez.push_back((ptr - &b[0]) - (a.size() - rest.size())) ;

    return 1 ;
}

int main()
{
    cin >> a >> b ;

    aflarest() ;

    char *ptr = &b[0] ;

    while(ptr = strstr(ptr, &a[0]))
    {
        rez.push_back((ptr - &b[0])) ;

        ptr += a.size() ;

        while(incaunul(ptr))
            ptr += rest.size() ; /// ???
    }

    cout << rez.size() << endl ;

    for(int f = 0 ; f < rez.size() ; f ++)
        cout << rez[f] << " " ;

    return 0 ;
}