Pagini recente » Cod sursa (job #902959) | Cod sursa (job #572752) | Cod sursa (job #445288) | Cod sursa (job #1920075) | Cod sursa (job #2974183)
#include <fstream>
using namespace std;
ifstream cin("strmatch.in");
ofstream cout("strmatch.out");
char a[2000001],b;
short int s[2000001];
long long nr1=1000000003,nr2=66666013,nr3,nr4=0,nr5=0,nr6=0,nr7=0,x=1,y=1,j;
int main()
{
int n,i=0;
cin>>a;
///cin>>b;
for(j=0;a[j]!=NULL && a[j]!='\n';j++){
if(a[j]>='A' && a[j]<='Z')
nr3=a[j]-'A'+1;
else
if(a[j]>='a' && a[j]<='z')
nr3=26+a[j]-'a'+1;
else
if(a[j]>='0' && a[j]<='9')
nr3=52+a[j]-'0'+1;
nr4*=62;
nr5*=62;
nr4+=nr3;
nr5+=nr3;
nr4%=nr1;
nr5%=nr2;
x=x*62%nr1;
y=y*62%nr2;
}
x/=62;
y/=62;
while(cin>>b){
if(b>='A' && b<='Z')
nr3=b-'A'+1;
else
if(b>='a' && b<='z')
nr3=26+b-'a'+1;
else
if(b>='0' && b<='9')
nr3=52+b-'0'+1;
s[i]=nr3;
if(i>j-1){
nr6-=(s[i-j]*x + nr1)%nr1;
nr7-=(s[i-j]*y + nr2)%nr2;
///cout<<nr6<<" "<<nr7<<'\n';
nr6=nr6*62%nr1;
nr7=nr7*62%nr2;
nr6+=nr3;
nr7+=nr3;
nr6%=nr1;
nr7%=nr2;
if(nr6==nr4 && nr7==nr5)
cout<<i-j+1<<" ";
}
else{
nr6*=62;
nr7*=62;
nr6+=nr3;
nr7+=nr3;
nr6%=nr1;
nr7%=nr2;
if(nr6==nr4 && nr7==nr5)
cout<<i-j+1<<" ";
}
i++;
}
return 0;
}