Cod sursa(job #2662251)

Utilizator radu16012003Radu Dumitrache radu16012003 Data 23 octombrie 2020 18:54:27
Problema Potrivirea sirurilor Scor 40
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
#include <cstring>
#define nmax 2000001
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char s[nmax],a[nmax];
int nr,v[1001],cnt;
int main()
{
    fin>>a;
    fin>>s;
    int poz=strstr(s,a)-s;
    while (poz>=0)
    {
        cnt++;
        if (cnt<=1000)
            v[cnt]=poz;
        if (strstr(s+poz+1,a)==NULL)
            poz=-1;
        else
            poz=strstr(s+poz+1,a)-s;
    }
    fout<<cnt<<'\n';
    for (int i=1;i<=cnt;i++)
        fout<<v[i]<<' ';

    return 0;
}