Cod sursa(job #2869608)

Utilizator beingsebiPopa Sebastian beingsebi Data 11 martie 2022 18:08:02
Problema Potrivirea sirurilor Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.74 kb
#include <bits/stdc++.h>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
// #define f cin
// #define g cout
string s, ax;
int lps[4000009], nd, tot;
vector<int> rez;
int32_t main()
{
    f >> s;
    nd = s.size();
    s += '~';
    f >> ax;
    s += ax;
    for (int i = 1, j; i < (int)s.size(); i++)
    {
        j = lps[i - 1];
        while (j && s[i] != s[j])
            j = lps[j - 1];
        if (s[i] == s[j])
            j++;
        lps[i] = j;
        if (lps[i] == nd)
        {
            tot++;
            if (rez.size() < 1000)
                rez.push_back(i - nd - nd);
        }
    }
    g << tot << '\n';
    for (const int &i : rez)
        g << i << " ";
    return 0;
}