Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- divisor = '#';
- var
- s,p,z : string;
- k,i,d : longint;
- pre : array [1..10000] of longint;
- begin
- assign(input,'input.txt'); reset(input);
- assign(output,'output.txt'); rewrite(output);
- readln(s);
- readln(p);
- z:=p+divisor+s;
- d:=length(z);
- pre[1]:=0;
- k:=0;
- for i:=2 to d do begin
- while (k<>0) and (z[k+1]<>z[i]) do begin
- k:=pre[k];
- end;
- if (z[k+1]=z[i])
- then inc(k);
- pre[i]:=k;
- end;
- for i:=1 to d do
- if (pre[i]=length(p))
- then begin
- writeln(i-2*length(p));
- break;
- end;
- close(input); close(output);
- end.
Add Comment
Please, Sign In to add comment