Pagini recente » Cod sursa (job #3124746) | Cod sursa (job #908880) | Cod sursa (job #2832580) | Cod sursa (job #963139) | Cod sursa (job #3321243)
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
using namespace std;
constexpr const int NMAX=1e6+8;
constexpr const ll mod=1e9+7;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
string a,b;
int pi[4*NMAX];
void solve()
{
fin >> a >> b;
int n=int(a.size());
a=a+"#"+b;
for(int i=1; i<(int)a.size(); i++)
{
int j=pi[i-1];
while(j>0 && a[i]!=a[j])
j=pi[j-1];
if(a[i]==a[j])
j++;
pi[i]=j;
}
vector<int> occ;
for(int i=n+1; i<(int)a.size(); i++)
{
if(pi[i]==n)
occ.pb(i-2*n);
}
fout << (int)occ.size() << "\n";
for(int i=0; i<min(1000,(int)occ.size()); i++)
fout << occ[i] << " ";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tests=1;
// cin >> tests;
for(int i=1; i<=tests; i++)
solve();
return 0;
}