Cod sursa(job #2343908)

Utilizator AndreiGSGhiurtu Andrei AndreiGS Data 14 februarie 2019 15:09:17
Problema Potrivirea sirurilor Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.9 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("strmatch.in");
ofstream fout("strmatch.out");

char s1[2000000], s2[2000000];
int n1, n2;
int index[2000000];
int ap[2000000], k;
int aparitii;
void indexare()
{
    int j = 0;
    for(int i = 0; i < n2; i++)
    {
        if(j == n1)
        {
            aparitii++;
            ap[k++] = i - j;
            i -= n1;
            j = 0;
        }
        else if(s1[j] == s2[i])
        {
            index[i] = index[i-1] + 1;
            j++;
        }
        else
        {
            j = 0;
            index[i] = 0;
        }
    }
}

int main()
{
    fin.getline(s1, 2000000);
    n1 = strlen(s1);
    fin.getline(s2, 2000000);
    n2 = strlen(s2);

    indexare();

    fout << aparitii << '\n';
    for(int i = 0; i < k; i++)
        fout << ap[i] << " ";



    return 0;
}