Pagini recente » Cod sursa (job #1517230) | Cod sursa (job #1335250) | Cod sursa (job #2692230) | Cod sursa (job #1164318) | Cod sursa (job #945888)
Cod sursa(job #945888)
program abc2;
var s:ansistring;
str:string;
l:integer;
a:array [0..7000000] of byte;
hash,ans:int64;
p:array[1..20] of int64;
i:longint;
buf:array[1..100000]of byte;
begin
assign(input,'abc2.in');
reset(input);
settextbuf(input,buf);
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]*2;
for i:=1 to l do hash:=hash+(ord(str[i])-ord('a')+1)*p[i];
a[hash]:=1;
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];
a[hash]:=1;
end;
hash:=0;
for i:=1 to l do
begin
hash:=hash+(ord(s[i])-ord('a')+1)*p[i];
end;
if a[hash]=1 then inc(ans);
for i:=l+1 to length(s) do
begin
hash:=hash-(ord(s[i-l])-ord('a')+1);
hash:=hash div 2;
hash:=hash+(ord(s[i])-ord('a')+1)*p[l];
if a[hash]=1 then inc(ans);
end;
writeln(ans);
close(input);close(output);
end.