Pagini recente » Profil LERVS_Ciocan_Craiu_Gemene | Cod sursa (job #1610354) | Cod sursa (job #2369742) | Cod sursa (job #110263) | Cod sursa (job #3213772)
#include <fstream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
using pii = pair<int,int>;
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");
const int base = 257;
const int mod = 1e9 + 7;
string a , b;
long long pw = 1;
vector <int> ans;
int cnt;
signed main()
{
cin >> a >> b;
for(int i = 1 ; i < a.size() ; ++i) pw = (pw * base) %mod;
long long h = 0 , h2 = 0;
for(int i = 0 ; i < a.size() ; ++i)
{
h = (h * base %mod + a[i])%mod;
h2 = (h2 * base %mod + b[i])%mod;
}
cout << h << '\n';
for(int i = 0 ;; ++i)
{
if(h == h2)
{
++cnt;
if(ans.size() < 1000) ans.push_back(i);
}
h2 -= (pw*b[i])%mod;
while(h2 < 0) h2 += mod;
if(i + a.size() < b.size()) h2 = (h2*base%mod + b[i + a.size()])%mod;
else break;
}
cout << cnt << '\n';
for(auto it : ans) cout << it << ' ';
return 0;
}