Pagini recente » Cod sursa (job #1665980) | Cod sursa (job #723239) | Cod sursa (job #2685594) | Cod sursa (job #2158328) | Cod sursa (job #945909)
Cod sursa(job #945909)
program abc2;
type lista=^celula;
celula=record
info:int64;
next:lista;
end;
var s:ansistring;
str:string;
l:integer;
a:array [0..1000003] of lista;
hash,ans:int64;
p:array[1..20] of int64;
i,x:longint;
buf:array[1..100000]of byte;
r:lista;
b:boolean;
begin
assign(input,'abc2.in');
reset(input);
assign(output,'abc2.out');
rewrite(output);
readln(s);
readln(str);
{ l:=length(str);
p[1]:=1;
for i:=2 to 20 do p[i]:=p[i-1]*3;
for i:=1 to l do hash:=hash+(ord(str[i])-ord('a')+1)*p[i];
new(r);
r^.info:=hash;
x:=hash mod 1000003;
r^.next:=a[x];
a[x]:=r;
while not eof do
begin
}readln(str);{
hash:=0;
for i:=1 to l do hash:=hash+(ord(str[i])-ord('a')+1)*p[i];
new(r);
r^.info:=hash;
x:=hash mod 1000003;
r^.next:=a[x];
a[x]:=r;
end;
hash:=0;
for i:=1 to l do
begin
hash:=hash+(ord(s[i])-ord('a')+1)*p[i];
end;
x:=hash mod 1000003;
r:=a[x];
b:=false;
r:=a[x];
while (r<>nil) and (not b) do
begin
if hash=r^.info then b:=true;
r:=r^.next;
end;
if b then inc(ans);
for i:=l+1 to length(s) do
begin
hash:=hash-(ord(s[i-l])-ord('a')+1);
hash:=hash div 3;
hash:=hash+(ord(s[i])-ord('a')+1)*p[l];
x:=hash mod 1000003;
r:=a[x];
b:=false;
r:=a[x];
while (r<>nil) and (not b) do
begin
if hash=r^.info then b:=true;
r:=r^.next;
end;
if b then inc(ans);
end;
writeln(ans); }
close(input);close(output);
end.