Pagini recente » Cod sursa (job #574347) | Cod sursa (job #1503795) | Cod sursa (job #2961151) | Cod sursa (job #1566880) | Cod sursa (job #2483447)
#include <iostream>
#include <fstream>
#include <string.h>
#include <algorithm>
using namespace std;
ifstream in("strmatch.in");
ofstream out("strmatch.out");
const int DIM = 2000005;
const int nr = 52;
char a[DIM];
char b[DIM];
long long power[DIM];
long long rez[DIM];
int main()
{
/*functia hash se face cu puterile nr de litere posibile din vector in cazul acesta sunt nr de litere mici si mari din alfabet englez adica 52 */
in >> a;
in >> b;
int K = 0;
power[0] = 1;
int A = strlen(a);
for(int i = 1;i <= A;i++)
{
power[i] = power[i - 1] * nr;
}
int B = strlen(b);
if(A > B)
{out << 0;
return 0;
}
long long S = 0;
long long val = 0;
for(int i = 0;i < A;i++)
{
val += power[A - i - 1] * (int(a[i]) - 47);
S += power[A - i - 1] *(int (b[i]) - 47);
}
if(S == val)
{K++;
rez[K] = 0;
}
for(int i = 1; i <= B - A;i++)
{
S = (S - power[A - 1] * (int(b[i-1]) - 47)) * nr + (int(b[i + A - 1]) - 47);
if(S == val)
{
K++;
rez[K] = i;
}
}
out << K<<"\n";
/* normal K ,in cazul asta e restrictie de 1000 de afisari*/
for(int i = 1; i <= min(1000,K); i++)
out << rez[i] <<" ";
return 0;
}