Cod sursa(job #2107267)

Utilizator octavian.sndOctavian Sandu octavian.snd Data 16 ianuarie 2018 22:06:50
Problema Potrivirea sirurilor Scor 18
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
char A[2000005], B[2000005], *p;
int n, x, v[50];

int main()
{
    f>>B;
    f>>A;
    if(B[0]==B[strlen(B)-1]) x=1;
    int k=0, q=0;
    p=strstr(A, B);
    while(p && k<=1000)
    {
        k++;
        n=p-A;
        if(q==0) v[++q]=n;
        else v[++q]=n+(strlen(B)-x)*(q-1);
        strcpy(A+n, A+n+strlen(B)-x);
        p=strstr(A, B);
    }
    g<<k<<endl;
    for(int i=1;i<=q;i++) g<<v[i]<<" ";
    return 0;
}