Cod sursa(job #945888)

Utilizator RusuAlexeiRusu Alexei RusuAlexei Data 3 mai 2013 11:40:42
Problema Abc2 Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 1.05 kb
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.