Pagini recente » Cod sursa (job #1790835) | Cod sursa (job #2476535) | Solutii FMI No Stress 4 | Cod sursa (job #2837121) | Cod sursa (job #1963085)
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
char sir[100003];
int L, l, k, j, contor;
short p[1003], ap[1003];
char c[1003];
int main()
{
fin>>c;
fin>>sir;
l = strlen(c);
L = strlen(sir);
k = 0;
for(j = 1; j < l; ++j)
{
if(c[j] == c[k])
{
++k;
p[j] = k;
}
else
{
k = 0;
p[j] = 0;
}
}
contor = 0;
k = 0;
for(j = 0; j < L; ++j)
{
if(c[k] == sir[j])
{
++k;
if(k == l)
{
ap[contor] = j - l + 1;
++contor;
k = p[l - 1];
}
}
else
{
if(k)
{
k = p[k - 1];
if(k)
{
--j;
}
}
}
}
fout<<contor<<'\n';
for(j = 0; j < contor; ++j)
{
fout<<ap[j]<<endl;
}
return 0;
}