Cod sursa(job #2709276)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 20 februarie 2021 09:42:23
Problema Potrivirea sirurilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.68 kb
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <climits>
#include <queue>

#define MOD 666013

using namespace std;

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

vector<int> v ;

int process(string a)
{

    int k = 0 ;


    for(int f = a.size() - 1 ; f >= 0 ; f --)
    {

        /// dau match la primele f caract si ultimele f caract

        string st = a.substr(0, f) ;
        string dr = a.substr(a.size() - f, a.size()) ;

        if(st == dr)return a.size() - f ;

    }

    return a.size() ;

}

int main()
{

    string a, b ;

    cin >> a >> b ;

    int k = process(a) ;

    string remainder = a.substr(a.size() - k, a.size() - k + a.size() - k) ; /// pe asta il cautam de la capat, daca este prezent acolo atunci continuam altfel doar cautam de la capat tot striungul

    return 0 ;

    char *ptr = &b[0], *auxptr ;

    while(auxptr = strstr(ptr, &a[0]))
    {

        v.push_back(auxptr - &b[0]) ;

        /// lam gasit pe a in auxptr
        /// acuma trebe sa vedem daca la sfarsitul lui a se afla remainder

        int poz = auxptr - &b[0] + a.size() ;

        while(b.substr(poz, remainder.size()) == remainder)
        {

            poz += remainder.size() ; /// poz devine sfarsitul lui remainder

            v.push_back(poz - a.size()) ;

        }

        ptr = &b[poz] ;

        ///ptr = auxptr + k ;

    }

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

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

    return 0 ;
}