Pagini recente » Cod sursa (job #69184) | Cod sursa (job #1580637) | Cod sursa (job #345176) | Cod sursa (job #46014) | Cod sursa (job #2720457)
#include <iostream>
#include <fstream>
#include <vector>
#define NMAX 2000000
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
string s1, s2;
int phi[2*NMAX+10], ans;
vector <int> v;
int main()
{
fin >> s1 >> s2;
string s = s1 + '%' + s2;
int len1 = s1.size(), len = s.size(), i = 1, j = 0;
while(i < len)
{ if(s[i] == s[j])
{ phi[i] = j + 1;
i++;
j++;
}
else
{ if(j)
j = phi[j-1];
else
i++;
}
}
for(int i=0; i<len; i++)
if(phi[i] == len1)
{ ans++;
if(v.size() < 1000)
v.push_back(i - 2 * len1);
}
fout << ans << '\n';
for(auto u : v)
fout << u << ' ';
fout << '\n';
return 0;
}