Pagini recente » Cod sursa (job #2260092) | Cod sursa (job #192389) | Cod sursa (job #921837) | Cod sursa (job #2172942) | Cod sursa (job #2023628)
#include <fstream>
#include <vector>
#include <string>
#define Nmax 2000005
using namespace std;
string A,B;
int pi[Nmax],w;
ifstream f("strmatch.in");
ofstream g("strmatch.out");
vector <int> rez;
int main()
{
int i,cnt=0;
f>>A>>B;
for(i=1; i<A.size(); i++)
{
while(w!=0 && A[i]!=A[w]) w=pi[w-1];
if(A[i]==A[w])
w++;
pi[i]=w;
}
w=0;
for(i=0; i<B.size(); i++)
{
while(w!=0 && B[i]!=A[w]) w=pi[w-1];
if(B[i]==A[w])
w++;
if(w==A.size())
{
cnt++;
if(cnt<=1000)
rez.push_back(i-A.size()+1);
}
}
g<<cnt<<'\n';
for(auto it:rez)
g<<it<<" ";
return 0;
}