Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- p = 31;
- var
- h,pow:array[0..255] of longint;
- s,t:string;
- i,j,n,h_,h_s:longint;
- e:boolean;
- Begin
- readln(t);
- readln(s);
- pow[1]:=1;
- for i:=2 to length(t) do
- pow[i]:=pow[i - 1] * p;
- for i:=1 to length(t) do
- h[i]:=(ord(t[i]) - 96) * pow[i] + h[i - 1];
- for i:=1 to length(s) do
- h_s:=h_s+(ord(s[i]) - 96) * pow[i];
- for i:=1 to length(t) - length(s) + 1 do
- begin
- h_:=h[i+length(s) - 1] - h[i - 1];
- if h_ = h_s * pow[i] then e:=true;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment