Pagini recente » Profil radub | Profil Tzapesh | Profil sorrow | Cod sursa (job #1427927) | Cod sursa (job #1427960)
#include<fstream>
#include<string>
#include<sstream>
#define P 101
#define MOD 100000007
using namespace std;
ifstream fin("strmatch.in");
ofstream fout("strmatch.out");
int i,j,s;
stringstream result;
string a,b;
long long pow;
long long ha, hb;
int main()
{
fin>>a;
fin>>b;
if(a.length()>b.length())
{
fout<<0;
return 0;
}
pow=1;
for(i=0; i<a.length(); ++i){
ha+=pow*a[a.length()-i-1];
pow*=P;
}
pow=1;
for(i=0; i<a.length(); ++i)
{
hb+=pow*b[a.length()-i-1];
pow*=P;
}
for(i=0; i<b.length()-a.length()+1; ++i)
{
if(ha==hb)
{
bool q=true;
if(q){
if(s<1000)
result<<i<<" ";
s++;
}
}
hb=P*(hb-pow*b[i]) + b[i+a.length()];
}
fout<<s<<endl;
fout<<result.str();
return 0;
}