Cod sursa(job #2855198)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 22 februarie 2022 10:58:00
Problema Potrivirea sirurilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.19 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") ;

/// 9:33

string a, b, rest ;

void aflarest()
{
    string auxa = a ;

    for(int f = 1 ; f < a.size() - 1 ; 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) ;
    }
}

bool incaunul(char *ptr)
{
    cout << ptr << endl ;

    for(int f = 0 ; f < rest.size() ; f ++)
        if(ptr[f] != rest[f])return 0 ;

    cout << (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]))
    {
        cout << (ptr - &b[0]) << " " ;

        ptr += a.size() ;

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

    /// daca lam gasit pe a in b putem face o optimizare, facem matching manual la rest in spatele a-ului gasit

    return 0 ;
}