Pagini recente » Monitorul de evaluare | Cod sursa (job #342299) | Monitorul de evaluare | Cod sursa (job #963145) | Cod sursa (job #3321241)
#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);
if(int(occ.size())==1000)
break;
}
fout << (int)occ.size() << "\n";
for(const auto it:occ)
fout << it << " ";
}
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;
}