Pagini recente » Cod sursa (job #2404942) | Cod sursa (job #3037747) | Cod sursa (job #3251338) | Cod sursa (job #3040662) | Cod sursa (job #3225418)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
string a,b,s;
vector<int> sol;
int ans=0;
int pi[4000005];
void prefix()
{
pi[0]=0;
for(int i=1;i<s.size();i++)
{
int j=pi[i-1];
while(j>0&&s[i]!=s[j])
j=pi[j-1];
if(s[i]==s[j])
j++;
pi[i]=j;
}
}
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>a>>b;
s=a+"#"+b;
prefix();
for(int i=a.size();i<s.size();i++)
if(pi[i]==a.size())
{
ans++;
if(sol.size()<1000)
sol.push_back(i-2*(int)a.size());
}
fout<<ans<<'\n';
for(int i:sol)
fout<<i<<' ';
return 0;
}