Cod sursa(job #2676372)

Utilizator Casian_doispeChiriac Casian Casian_doispe Data 24 noiembrie 2020 09:56:23
Problema Potrivirea sirurilor Scor 18
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.48 kb
#include <fstream>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <cstring>
#include <set>
#define MOD 1234

using namespace std ;

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

string a, b, simplificat ;

vector<int> v ;

string simplifica(string a)
{

    int mx = 0 ;

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

        int ok = 1 ;

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

            if(a[e] != a[g]){ok = 0; break;} ;

        }

        if(ok)mx = f ;

    }

    for(int f = 0 ; f <= mx ; f ++)a = &a[1] ;

    return a ;

}

bool nextup(char *ptr)
{

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

        return 0 ;

    }

    return 1 ;

}

int main()
{

    cin >> a >> b ;

    simplificat = simplifica(a) ;

    char *ptr = &b[0] ;

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

        ptr = strstr(ptr, &a[0]) ;

        if(!ptr)break ;

        v.push_back(ptr - &b[0] + 1) ;

        ptr += a.size() ;

        while(nextup(ptr))
        {

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

            ptr += simplificat.size() ;

        }

    }

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

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

    return 0 ;

}