Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.61 KB | None | 0 0
  1. program Arina;
  2. var
  3.   s,s1: ansistring;
  4.   i, k, n,prov: word;
  5.   pref: array of word;
  6.   sum: word;
  7. begin
  8.   Assign(input, 'input.txt');
  9.   Assign(output, 'output.txt');
  10.   reset(input);
  11.   rewrite(output);
  12.   Readln(s1);
  13.   readln(s);
  14.   n:=length(s1);
  15.   s:=s1+' '+s;
  16.   s1:= '';
  17.   setlength(pref,Length(s)-n);
  18.   k := 0;
  19.   prov:=Length(s)-n+1;
  20.   for i := n+1 to Length(s) do
  21.   begin
  22.     while (k > 0) and (s[k + 1] <> s[i]) do
  23.       k := pref[k];
  24.     if s[k + 1] = s[i] then
  25.       k += 1;
  26.     pref[i] := k;
  27.     if pref[i]=n then
  28.       sum += 1;
  29.   end;
  30.   Write(sum);
  31.   Close(input);
  32.   Close(output);
  33. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement