Pagini recente » Cod sursa (job #1294825) | Profil dickmeister191 | Cod sursa (job #2763940) | Cod sursa (job #549957) | Cod sursa (job #1880943)
#include <fstream>
#include <vector>
#define VAL 2000005
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
int LP, LT, i, j;
int FF[VAL], poz, K;
string P, T;
vector<int> ANS;
int main()
{
fin >> P >> T;
LP=P.size();
LT=T.size();
P='*'+P;
T='*'+T;
for (i=2; i<=LP; i++)
{
poz=FF[i-1];
while (poz>0 && P[i]!=P[poz+1])
poz=FF[poz];
if (P[i]==P[poz+1])
FF[i]=poz+1;
}
poz=0;
for (i=1; i<=LT; i++)
{
while (poz>0 && T[i]!=P[poz+1])
poz=FF[poz];
if (T[i]==P[poz+1])
poz++;
if (poz==LP)
ANS.push_back(i+1-LP);
}
K=ANS.size();
fout << K << '\n';
for (i=0; i<=min(K-1, 999); i++)
fout << ANS[i] << " ";
fin.close();
fout.close();
return 0;
}