Pagini recente » Cod sursa (job #2057642) | Istoria paginii runda/rf_2/clasament | Cod sursa (job #1837343) | Cod sursa (job #1038769) | Cod sursa (job #1219943)
#include <fstream>
#include <string>
#define maxN 4000050
#define minim(a, b) ((a < b) ? a : b)
using namespace std;
string S1,S2;int Pi[maxN],Answer[maxN],i,A,B,sol,k(0);
int main()
{ifstream cin("strmatch.in");ofstream cout("strmatch.out");
getline(cin,S1);getline(cin,S2);
A=S1.size(); S1+='#'+S2; Pi[0]=0;
for (i=1;i<S1.size();++i){
while (k>0 && S1[i]!=S1[k]) k=Pi[k-1];
if (S1[i]==S1[k]) ++k; Pi[i]=k;}
for (i=A+1;i<=S1.size()-1;++i)
if (Pi[i]==A)Answer[++sol]=i-2*A;
cout<<sol<<"\n"; for (i=1;i<=min(sol,1000);++i)cout<<Answer[i]<<" ";
return 0;}