Pagini recente » Cod sursa (job #3363193) | Cod sursa (job #3363200) | Cod sursa (job #3363146) | Cod sursa (job #3363156) | Cod sursa (job #3363168)
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int BAZA = 67;
const int MOD = 10e9 + 7;
const int CIF_MAX = 1000;
int cod[BAZA + 1], h[CIF_MAX + 1], inv[CIF_MAX + 1];
int hs(string s, int b)
{
int put, nr = 1;
put = 1;
for(int i = 0; i < s.size(); i++)
{
nr = 1LL * nr * ((1LL * (cod[(s[i] - '0') % BAZA]) * put) % MOD) % MOD;
put = (1LL * put * b) % MOD;
}
return nr;
}
void hp(string s, int b)
{
int put = 1, nr = 1;
for(int i = 0; i < s.size(); i++)
{
nr = 1LL * nr * ((1LL * cod[s[i] - '0'] * put) % MOD) % MOD;
put = 1LL * put * b % MOD;
h[i + 1] = nr;
}
}
int put(int a, int b)
{
if(b == 1)
return a;
if(b == 0)
return 1;
if(b % 2 == 1)
{
return 1LL * (1LL * put(1LL * a * a % MOD, b / 2) * a % MOD) * a % MOD;
}
else
{
int rez = put(a, b / 2);
return 1LL * rez * rez % MOD;
}
}
signed main()
{
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int ha, hb, poz = 0, chb = 0, lenb = 0;
string a, b;
char c;
cin >> b >> a;
for(c = 'a'; c <= 'z'; c++)
{
cod[(c - '0') % BAZA] = poz;
poz++;
}
for(int i = 0; i < 10; i++)
{
cod[i % BAZA] = poz;
poz++;
}
for(c = 'A'; c <= 'Z'; c++)
{
cod[(c - '0') % BAZA] = poz;
poz++;
}
cin >> a >> b;
hb = hs(b, BAZA);
chb = hb;
while(chb > 0)
{
chb /= 10;
lenb++;
}
hp(a, BAZA);
for(int i = 0; i <= CIF_MAX; i++)
{
inv[i] = put(BAZA, (1LL * i + MOD - 2) % MOD);
}
for(int i = lenb; i <= a.size(); i++)
{
if((h[i] - h[i - lenb]) * inv[lenb] == hb)
{
cout << i << " ";
}
}
return 0;
}