Pagini recente » Rating jumarea stefan (stefanjumarea02) | Cod sursa (job #1759532) | Cod sursa (job #1121696) | Cod sursa (job #1800518) | Cod sursa (job #1880897)
#include <fstream>
#include <vector>
#define VAL 2000005
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
int N, M, i, j;
int FF[VAL], poz;
string S, T;
vector<int> ANS;
vector<int> :: iterator it;
int main()
{
fin >> S >> T;
N=S.size();
M=T.size();
S='*'+S;
T='*'+T;
for (i=1; i<N; i++)
{
poz=FF[i];
while (poz>0 && S[i+1]!=S[poz+1])
poz=FF[poz-1];
if (S[i+1]==S[poz+1])
FF[i+1]=poz+1;
}
poz=0;
for (i=1; i<M; i++)
{
while (poz>0 && T[i+1]!=S[poz+1])
poz=FF[poz-1];
if (T[i+1]==S[poz+1])
poz++;
if (poz==N)
ANS.push_back(i+1-N);
//fout << poz << " ";
}
//fout << '\n';
fout << ANS.size() << '\n';
for (it=ANS.begin(); it!=ANS.end(); it++)
fout << *it << " ";
fin.close();
fout.close();
return 0;
}